Django 基础
Posted ckjlt1995
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django 基础相关的知识,希望对你有一定的参考价值。
创建Django项目(需要从终端输入):
Django-admin startproject 项目名称
创建app应用文件
首先 cd 你所创建项目的目录中
cd 项目名称
python manage.py startapp 应用名称
需要从你的项目里的settings.py进行配置
INSTALLED_APPS = [
"""
‘app01‘,
‘app02‘,
‘rest_framework‘,
‘corsheaders‘
]
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‘,
‘corsheaders.middleware.CorsMiddleware‘,
]
#配置汉化
LANGUAGE_CODE = ‘zh-hans‘
TIME_ZONE = ‘Asia/Shanghai‘
USE_I18N = True
USE_L10N = True
USE_TZ = False
# 添加跨域配置
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = ()
CORS_ALLOW_METHODS = (
‘DELETE‘,
‘GET‘,
‘OPTIONS‘,
‘PATCH‘,
‘POST‘,
‘PUT‘,
‘VIEW‘,
)
CORS_ALLOW_HEADERS = (
‘XMLHttpRequest‘,
‘X_FILENAME‘,
‘accept-encoding‘,
‘authorization‘,
‘content-type‘,
‘dnt‘,
‘origin‘,
‘user-agent‘,
‘x-csrftoken‘,
‘x-requested-with‘,
‘Pragma‘,
)
以上是关于Django 基础的主要内容,如果未能解决你的问题,请参考以下文章
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段