manager.py:
- 是django用于管理本项目的命令行工具,之后进行站点运行,数据库自动生成等都是通过本文件完成。
djangoStudy/__init__.py:
- 告诉python该目录是一个python包,暂无内容,后期一些工具的初始化可能会用到。
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:
- 维护项目的url路由映射,即定义当客户端访问路由时由哪个模块进行响应。
djangoStudy/wsgi.py:
- 全称为Python Web Server Gateway Interface,即Python服务器网关接口,是Python应用与Web服务器之间的接口,用于django项目在服务器上的部署和上线,一般不需要修改。
djangoStudy/asgi.py:
- 定义ASGI的接口信息,和WSGI类似,在3.0以后新增ASGI,相比WSGI,ASGI实现了异步处理,用于启动异步通信服务,比如:实现在线聊天等异步通信功能。(类似Tornado异步框架)
参考视频:https://www.bilibili.com/video/BV1fh4y1Z7jp/?p=5