Skip to content

lyonyang/django-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Docs

django-version python-version django-docs

安装

$ pip install django-apidocs

快速开始

settings.py , INSTALLED_APPS 添加 django_docs

INSTALLED_APPS = [
    '...',
    'django_docs'
]

在项目根 urls.py 中, 添加文档路由

url(r'^django_docs/', include('django_docs.urls')),

启动项目, 访问 ip:port/django_docs/login/ , 输入任意用户名密码登录

编写API

新建目录与文件 api/article.py

使用原始的 ViewJsonResponse

from django_docs import docs_define
from django.views import View
from django.http import JsonResponse

class ArticleList(View):
    @docs_define('/article/list', desc='文章列表')
    def get(self, request):
        data = [
            {
                'title': 'django-docs',
                'author': 'lyon',
                'content': 'This is a Django application. Help you build Web API quickly.'
            },
            {
                'title': 'django-docs-desc',
                'author': 'lyon',
                'content': 'Efficient, Simple and Flexible.'
            }

        ]
        return JsonResponse(data, safe=False)

使用 BaseHandler

from django_docs import docs_define, BaseHandler

class ArticleList(BaseHandler):
    @docs_define('/article/list', desc='文章列表')
    def get(self, request):
        data = [
            {
                'title': 'django-docs',
                'author': 'lyon',
                'content': 'This is a Django application. Help you build Web API quickly.'
            },
            {
                'title': 'django-docs-desc',
                'author': 'lyon',
                'content': 'Efficient, Simple and Flexible.'
            }

        ]
        return self.write(data)

注册 article.py

# settings.py

INSTALLED_HANDLERS = [
    'api.article', 
]

刷新文档

About

django-docs 高效率的构建Web API工具 🚀

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages