1,中间件:
文件可以创建在项目的任意位置,为了方便都是创建在app下面的目录
settings
MIDDLEWARE = [
请求从上往下,响应从下往上,
那层返回了响应就不会往下进行了,直接返回了
]
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',
'teacher.middleware.simple_middleware',
'teacher.middleware.SimpleMiddleWare'
]
2,上下文处理器:
创建文件:customer_context_processors
def my_name(request):
return {'name' : '心蓝'}
环境里面设置:
'teacher.customer_context_processors.my_name',
3,djangoadmin
******一定要做数据库迁移
python manage.py createsuperuser #创建一个超级用户的命令
admin:
list_display = ['id', 'name', 'sex', 'qq', 'phone'] ##模型里面字段名一一对应,和显示页一一对应