标签:[] templates doc admin djang lan wsgi serve sso
import os #向上找两级,获取基地址 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = ‘tt^-bhdmqd-^pet%puk*q58gcqg-g)9h+97!4m9aveddp_$%5e‘ DEBUG = True ALLOWED_HOSTS = [] #APP信息,自己新建的项目如果没有自动加入,可以再次手动加进去 INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘app01‘, ‘backend‘, ‘web‘, ] #中间件配置 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‘, # "app01.my_middlewares.AuthMiddleware", #注意自己写的中间件,配置要写在系统中的后面 ] ROOT_URLCONF = ‘myblog.urls‘ #模板(HTML页面)路径相关配置 TEMPLATES = [ { ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘, ‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)], ‘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‘, ], }, }, ] # #配置模板 # TEMPLATE_DIRS = ( # os.path.join(BASE_DIR,‘templates‘), # ) #网页服务网关协议消息 WSGI_APPLICATION = ‘myblog.wsgi.application‘ #原来默认的sqlite数据库 # DATABASES = { # ‘default‘: { # ‘ENGINE‘: ‘django.db.backends.sqlite3‘, # ‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘), # } # } #mysql数据库 同时需要设置__init__.py # import pymysql # pymysql.install_as_MySQLdb() DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, ‘NAME‘:‘myblog‘, #数据库名 ‘USER‘: ‘root‘, ‘PASSWORD‘: ‘‘, ‘HOST‘: ‘localhost‘, ‘PORT‘: 3306, } } #认证相关 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‘, }, ] # 语言 LANGUAGE_CODE = ‘zh-hans‘ # 主要针对admin页面 # 时间 TIME_ZONE = ‘Asia/Shanghai‘ USE_I18N = True USE_L10N = True #时区设置 USE_TZ = False #静态文件 STATIC_URL = ‘/static/‘ # 静态文件别名 STATICFILES_DIRS=( os.path.join(BASE_DIR,‘static‘), #主文件下静态文件 ) # 与用户上传相关的配置 #路由urls.py中也需要配置 """ # media配置: from django.urls import path,re_path from django.views.static import serve from django.conf import settings urlpatterns = [ re_path(r"media/(?P<path>.*)$",serve,{"document_root":settings.MEDIA_ROOT}), ] """ MEDIA_ROOT=os.path.join(BASE_DIR,"media") MEDIA_URL="/media/" # 引用Django自带的User表,继承使用时需要设置 #如果数据库中的UserInfo(用户表)继承django内置AbstractUser #model需导入 from django.contrib.auth.models import AbstractUser AUTH_USER_MODEL="app01.UserInfo" #应用名.UserInfo # 自定义配置登陆验证返回路径 LOGIN_URL="/login/" LOGIN_REDIRECT_URL = ‘/‘ LOGOUT_URL = ‘/logout/‘ # EMAIL_HOST = ‘smtp.exmail.qq.com‘ # 如果是 163 改成 smtp.163.com EMAIL_PORT = 465 EMAIL_HOST_USER = ‘‘ # 帐号 EMAIL_HOST_PASSWORD = ‘‘ # 密码 # DEFAULT_FROM_EMAIL = EMAIL_HOST_USER EMAIL_USE_SSL = True #session存储的相关配置 # Django默认支持Session,并且默认是将Session数据存储在数据库中,即:django_session表中。提供了5种类型的Session """ #1.数据库 SESSION_ENGINE = ‘django.contrib.sessions.backends.db‘ # 引擎(默认) #2.缓存 SESSION_ENGINE = ‘django.contrib.sessions.backends.cache‘ # 引擎 SESSION_CACHE_ALIAS = ‘default‘ # 要配合Django缓存配置 # 使用的缓存别名(默认内存缓存,也可以是memcache),此处别名依赖缓存的设置 #3.文件 SESSION_ENGINE = ‘django.contrib.sessions.backends.file‘ # 引擎 SESSION_FILE_PATH = None # 缓存文件路径,如果为None,则使用tempfile模块获取一个临时地址tempfile.gettempdir() #4.缓存+数据库 SESSION_ENGINE = ‘django.contrib.sessions.backends.cached_db‘ # 引擎 #5.加密cookie 基本没有用 SESSION_ENGINE = ‘django.contrib.sessions.backends.signed_cookies‘ # 引擎 """ # SESSION_COOKIE_NAME = "sessionid" # Session的cookie保存在浏览器上时的key,即:sessionid=随机字符串(默认) # SESSION_COOKIE_PATH = "/" # Session的cookie保存的路径(默认) # SESSION_COOKIE_DOMAIN = None # Session的cookie保存的域名(默认) # SESSION_COOKIE_SECURE = False # 是否Https传输cookie(默认) # SESSION_COOKIE_HTTPONLY = True # 是否Session的cookie只支持http传输(默认) # SESSION_COOKIE_AGE = 1209600 # Session的cookie失效日期(2周)(默认) # SESSION_EXPIRE_AT_BROWSER_CLOSE = False # 是否关闭浏览器使得Session过期(默认) # SESSION_SAVE_EVERY_REQUEST = True # (每次刷新更新时间) 是否每次请求都保存Session,默认修改之后才保存(默认) SESSION_COOKIE_AGE = 60 * 60 * 24 SESSION_SAVE_EVERY_REQUEST = True #打印日志到屏幕 LOGGING = { ‘version‘: 1, ‘disable_existing_loggers‘: False, ‘handlers‘: { ‘console‘:{ ‘level‘:‘DEBUG‘, ‘class‘:‘logging.StreamHandler‘, }, }, ‘loggers‘: { ‘django.db.backends‘: { ‘handlers‘: [‘console‘], ‘propagate‘: True, ‘level‘:‘DEBUG‘, }, } }
标签:[] templates doc admin djang lan wsgi serve sso
原文地址:https://www.cnblogs.com/bubu99/p/10317771.html