美文网首页django-rest-framework
django-restful:drf 文档介绍

django-restful:drf 文档介绍

作者: 你常不走的路 | 来源:发表于2018-01-07 11:41 被阅读18次

官网本身也有关于文档的配置
http://www.django-rest-framework.org/topics/documenting-your-api/

这里我就写文档配置 以及功能的简单记述

配置url

rom rest_framework.documentation import include_docs_urls

urlpatterns = [
    ...
    url(r'^docs/', include_docs_urls(title='My API title'))  #title 显示文档名字 可自行修改
]

给list create delete 等功能 加上描述

class UserList(generics.ListAPIView):  
    """
    get:
     get 方法的描述

    post:
    create 方法的描述
    """

同样 有一些 参数 也需要 描述 例如 /goods/{id}
同样 要告诉 前端 这个id 是什么

可以在 model serializer filters 中 加上 help_text 就可以了

    mobile = serializers.CharField(max_length=11,help_text='手机号')

同样它还支持 base session token 三种方式的登录 可自行选择

authentication.PNG

他还有 shell javaScript python 三种接口 调试

source Code.PNG

把 docs 和 apiRoot 结合 一起使用 非常方便

相关文章

网友评论

    本文标题:django-restful:drf 文档介绍

    本文链接:https://www.haomeiwen.com/subject/vpspnxtx.html