关于django休息框架文档,如何自定义请求参数的描述并将字段添加到post params?

时间:2017-12-21 10:35:33

标签: django django-rest-framework

enter image description here

在rest_framework.documentation的自动生成视图中,当我进行帖子测试时,没有字段来填充我的参数,以及如何添加请求参数的描述,例如"删除>列表&的api #34;

我无法从文档中获得这些想法:Documenting your API

我应该在这里写一些代码吗?

@api_view(['POST'])
def Login(request):

    try:
        username=request.data['username']
        password=request.data['password']
    except Exception as error:
        return Response(str(error), status=status.HTTP_400_BAD_REQUEST)
    user = authenticate(username=username, password=password)
    if user is None:

或:

from django.conf.urls import url, include
from django.contrib import admin
from . import views
from rest_framework.documentation import include_docs_urls

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^media/(?P<file_path>.*)', views.GetMediaFiles),
    url(r'^api/',include('api.urls')),
    url(r'^docs/', include_docs_urls(title='CLTools API Docs')),
]

谢谢!

0 个答案:

没有答案