manager.py:
djangoStudy/__init__.py:
djangoStudy/setting.py:
django项目的配置文件,默认状态其中定义了本项目引用的组件,项目名,数据库,静态资源等。
主要配置项:
from pathlib import Path
# 项目根目录
BASE_DIR = Path(__file__).resolve().parent.parent
# 项目的密钥,用作加密解密
SECRET_KEY = "django-insecure-_z)kge+g80*a54n9p2v3dt6)7@31oc5u+^1azzsczqc@d^^-jp"
# 是否使用调试模式,True为开启,一般用于开发过程中;False为关闭,一般用于上线部署
DEBUG = True
# 被允许的域名或IP
# * 代通配,即允许所有域名或IP访问项目
ALLOWED_HOSTS = ["*"]
# 定义项目中的应用
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# 定义自己的应用
"user",
]
# 定义中间件
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 = "djangoStudy.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目录
WSGI_APPLICATION = "djangoStudy.wsgi.application"
# Database
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
# 密码验证器
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 = "en-us" # 语言,zh-hans代表中文
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# 静态文件目录
STATIC_URL = "static/"
# 默认的主键字段类型
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
djangoStudy/urls.py:
djangoStudy/wsgi.py:
djangoStudy/asgi.py:
参考视频:https://www.bilibili.com/video/BV1fh4y1Z7jp/?p=5