django框架配置文件说明

Django框架settings.py文件介绍

# settings.py
"""
Django settings for demo project.

Generated by 'django-admin startproject' using Django 2.2.17.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# 自动获取项目所在路径 等同于 ../ ,项目中的路径都可使用路径拼接方法得到:os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# 项目密钥,生成项目时自动生成,可修改。用于保护项目账号安全。
SECRET_KEY = '#pi(q#h3yjtf@k(466+usu_*0$9(n1@)5axv1cnu5$w8ffdifb'

# SECURITY WARNING: don't run with debug turned on in production!
# 项目正式运营后,当关闭调试。
DEBUG = True
# 设置允许登录后端的IP或host,*代表任意网址都能登录后端。
ALLOWED_HOSTS = ['*']


# Application definition
# 应用注册
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
# 中间件
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',
]
# 总路由的位置
ROOT_URLCONF = 'demo.urls'
# 模板配置
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'demo.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
# 数据库配置
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
# 密码认证
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
# 设置语言
# LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'zh-hans'
# 设置时区
# TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Shanghai'
# 使用django翻译系统,关闭后可以优化性能。
USE_I18N = True
# 使用本地化数据格式,打开后使用当前区域的格式显示数字和日期。
USE_L10N = True
# 使用django内置的时区检测,开启后django自动检测时区。通常将其关闭。
# USE_TZ = True
USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

# 前端访问静态文件的路径:http://127.0.0.1:8001/static/静态文件(由于打开了酷狗,8000端口被酷狗占用,从而出错。故改用端口8001)
STATIC_URL = '/static/'
# STATIC_URL = '/'  # 访问静态文件的最简形式

# 设置静态文件路径,静态文件的寻找按列表顺序来,若静态文件重名,只会显示第一个静态文件。
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static_files'),
    os.path.join(BASE_DIR, 'static_photos'),
]


上一篇:解决django前端使用iframe标签报错127.0.0.1 refused to connect.


下一篇:jupyter_contrib_nbextensions安装