"""
Django settings for demo project.
Generated by 'django-admin startproject' using Django 4.2.3.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os.path
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
import os
os.environ['PYTHONIOENCODING'] = "utf-8"
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-jsp@68x83krx%uz-77(l0bd%+%b)mi(zn^n3@mxbioe-d!a49v'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api'
]
MIDDLEWARE = [
# # 下面这个缓存中间件必须放在所有中间件的最上面
# "django.middleware.cache.UpdateCacheMiddleware",
'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',
# # 下面这个缓存中间件必须放在所有中间件的最下面
# "django.middleware.cache.FetchFromCacheMiddleware",
]
ROOT_URLCONF = 'demo.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
# 'DIRS': [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',
],
},
},
]
WSGI_APPLICATION = 'demo.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'day07', # 你的数据库名称
'USER': 'root', # 你的数据库用户名
'PASSWORD': '123', # 你的数据库密码
'HOST': '', # 你的数据库主机,留空默认为localhost
'PORT': '3306', # 你的数据库端口
}
}
# LOGGING = {
# 'version': 1,
# 'disable_existing_loggers': False,
# 'handlers': {
# 'console':{
# 'level':'DEBUG',
# 'class':'logging.StreamHandler',
# },
# },
# 'loggers': {
# 'django.db.backends': {
# 'handlers': ['console'],
# 'propagate': True,
# 'level':'DEBUG',
# },
# }
# }
# CACHES = {
# 'default': {
# 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
# 'LOCATION': 'unique-snowflake',
# 'OPTIONS': {
# 'MAX_ENTRIES': 300, # 最大缓存个数(默认300)
# 'CULL_FREQUENCY': 3, # 缓存到达最大个数之后,剔除缓存个数的比例,即:3/CULL_FREQUENCY(默认3)
# },
# }
# }
# 我这里将cache缓存由本地内存缓存更换为了Redis
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://:@192.168.10.142:6379/2",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PASSWORD": "1234", # 密码,如果没有设置密码,这个参数可以注视掉
# 'MAX_ENTRIES': 300, # 最大缓存个数(默认300)
# 'CULL_FREQUENCY': 3, # 缓存到达最大个数之后,剔除缓存个数的比例,即:1/CULL_FREQUENCY(默认3)
}
}
}
# # 默认超时时间是300秒,我们可以通过CACHE_MIDDLEWARE_SECONDS来修改
# CACHE_MIDDLEWARE_SECONDS = 20
# # 下面是关于key的,咱们这里保持默认就完了
# CACHE_MIDDLEWARE_KEY_PREFIX = ""
# # 用于存储的缓存别名,没想好的,指定个default就行
# CACHE_MIDDLEWARE_ALIAS = "default"
# Password validation
# https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# 决定日志保存到哪个文件夹下?我这里将自动创建到项目根目录下的logs文件夹内
LOGS_DIRS = os.path.join(BASE_DIR, 'logs')
if not os.path.exists(LOGS_DIRS):
os.makedirs(LOGS_DIRS)
LOGS_DIRS = os.path.join(BASE_DIR, 'logs')
if not os.path.exists(LOGS_DIRS):
os.makedirs(LOGS_DIRS)
# # 日志
# LOGGING = {
# 'version': 1, # 使用的日志模块的版本,目前官方提供的只有版本1,但是官方有可能会升级,为了避免升级出现的版本问题,所以这里固定为1
# 'disable_existing_loggers': False, # 是否禁用其他的已经存在的日志功能?肯定不能,有可能有些第三方模块在调用,所以禁用了以后,第三方模块无法捕获自身出现的异常了。
# 'formatters': { # 日志格式设置,verbose或者simple都是自定义的
# 'verbose': { # 详细格式,适合用于开发人员不在场的情况下的日志记录。
# # 格式定义:https://docs.python.org/3/library/logging.html#logrecord-attributes
# # levelname 日志等级
# # asctime 发生时间
# # module 文件名
# # process 进程ID
# # thread 线程ID
# # message 异常信息
# 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
# 'style': '{', # 变量格式分隔符
# },
# 'simple': { # 简单格式,适合用于开发人员在场的情况下的终端输出
# 'format': '{levelname} {message}',
# 'style': '{',
# },
# },
# 'filters': { # 过滤器
# 'require_debug_true': {
# '()': 'django.utils.log.RequireDebugTrue',
# },
# },
# 'handlers': { # 日志处理流程,console或者mail_admins都是自定义的。
# 'console': {
# 'level': 'DEBUG', # 设置当前日志处理流程中的日志最低等级
# 'filters': ['require_debug_true'
没有合适的资源?快使用搜索试试~ 我知道了~
2024-Django平台开发-Django知识点(七)
共53个文件
py:21个
pyc:15个
xml:9个
0 下载量 160 浏览量
2024-01-14
11:53:35
上传
评论
收藏 54KB ZIP 举报
温馨提示
111
资源推荐
资源详情
资源评论
收起资源包目录
demo.zip (53个子文件)
demo
db.sqlite3 132KB
api
__init__.py 0B
tests.py 63B
admin.py 66B
migrations
__init__.py 0B
0001_initial.py 530B
__pycache__
0001_initial.cpython-310.pyc 644B
__init__.cpython-310.pyc 132B
apps.py 144B
models.py 180B
__pycache__
views.cpython-310.pyc 525B
__init__.cpython-310.pyc 121B
apps.cpython-310.pyc 394B
admin.cpython-310.pyc 162B
models.cpython-310.pyc 521B
views.py 2KB
demo
__init__.py 2KB
wsgi.py 401B
urls.py 339B
settings.py 14KB
__pycache__
__init__.cpython-310.pyc 429B
wsgi.cpython-310.pyc 519B
settings.cpython-310.pyc 3KB
urls.cpython-310.pyc 315B
asgi.py 401B
utils
tengxun.py 4KB
__init__.py 26B
huyi.py 3KB
ronglian.py 4KB
logger.py 187B
__pycache__
__init__.cpython-310.pyc 123B
logger.cpython-310.pyc 284B
demo.py 523B
templates
index.html 337B
.idea
dataSources
3cea9aa0-fe8a-4c1f-820e-be9cf9780cd3.xml 57KB
3cea9aa0-fe8a-4c1f-820e-be9cf9780cd3
storage_v2
_src_
schema
performance_schema.kIw0nw.meta 76B
sys.zb4BAA.meta 61B
information_schema.FNRwLQ.meta 76B
mysql.osA4Bg.meta 63B
a188790d-7ba8-4d5f-9914-5c89411d62e6.xml 60KB
dataSources.local.xml 2KB
workspace.xml 11KB
demo.iml 1KB
misc.xml 200B
dataSources.xml 2KB
inspectionProfiles
Project_Default.xml 969B
profiles_settings.xml 174B
modules.xml 267B
.gitignore 184B
manage.py 682B
my_signal.py 167B
logs
__pycache__
my_signal.cpython-310.pyc 184B
manage.cpython-310.pyc 798B
共 53 条
- 1
资源评论
一夜白头催人泪
- 粉丝: 8194
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功