- INSTALLED_APPS中增加
"rest_framework",
'rest_framework.authtoken', - settings.py中
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.Page
'PAGE_SIZE': 50,
'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S',
'DEFAULT_RENDER_CLASSES': [
'restframework.renders.JSONRender',
'restframework.renders.BorwsableAPIRender',
],
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser',
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
]
}
- urls.py
# urls.py文件增加路由。
# import include
from django.urls import include
# urlpatterns增加'rest_framework.urls'
urlpatterns = [
path('api-auth/', include('rest_framework.urls')),
]
标签:py,DEFAULT,配置,rest,framework,urls,DRF
From: https://www.cnblogs.com/chrjiajia/p/17369924.html