Django_项目基本配置

一、跨域处理

1.安装依赖

pip install django-cors-headers

2.注册应用

INSTALLED_APPS = [

        '''

         'corsheaders',
        '''

]

3.修改配置

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',
]

#支持所有用户跨域

CORS_ORIGIN_ALLOW_ALL = True

二、mysq数据库l配置

DATABASES = {

        'default': {

                 'ENGINE': 'django.db.backends.mysql',

                'NAME': 'shop',

                 'USER':'root',

                'PASSWORD':'root',

                'PORT':3306, 、

                'HOST':'localhost',

         }

}

三、时区配置

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

你可能感兴趣的:(Django,django,python,后端)