一、
安装方式:
pip install django
pip install djangorestframework
其他细节就不多说了
在setting中加入配置
INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘api.apps.ApiConfig‘, ‘rest_framework‘ ]
MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware‘,
‘django.contrib.sessions.middleware.SessionMiddleware‘,
‘django.middleware.common.CommonMiddleware‘,
‘django.middleware.csrf.CsrfViewMiddleware‘,
‘django.contrib.auth.middleware.AuthenticationMiddleware‘,
‘django.contrib.messages.middleware.MessageMiddleware‘,
‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,
‘api.cors.CORSMiddleware‘ # 可以跨域请求
]
# 开restful接口
REST_FRAMEWORK = {
‘DEFAULT_RENDERER_CLASSES‘: [‘rest_framework.renderers.JSONRenderer‘, ‘rest_framework.renderers.BrowsableAPIRenderer‘,],
‘DEFAULT_VERSIONING_CLASS‘: ‘rest_framework.versioning.URLPathVersioning‘,
‘ALLOWED_VERSIONS‘: [‘v1‘, ‘v2‘], # 允许的版本
‘VERSION_PARAM‘: ‘version‘, # 参数
‘DEFAULT_VERSION‘: ‘v1‘, # 默认版本
}
原文:https://www.cnblogs.com/taozhengquan/p/10046846.html