语言:LANGUAGE_CODE ='zh-Hans'
时区:TIME_ZONE ='Asia/Shanghai'
禁止csrf:# 'django.middleware.csrf.CsrfViewMiddleware'
链接数据库:
pip install mysqlclient
create database Django default charset utf8
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME':'Django',
'USER':'root',
'PASSWORD':'123456',
'HOST':'127.0.0.1',
'PORT':'3306'
}
}
创建应用:python manage.py startapp myapp
注册应用:INSTALLED_APPS = [myapp]
路由分发:myapp中创建子路由urls.py,主路由path('myapp/', include('myapp.urls'))
应用模板:myapp中创建应用模板文件夹templates/myapp
应用模型:myapp的model.py中创建模型类(数据库表)
数据迁移:python manage.py makemigrations python manage.py migrate
请求响应:myapp的view.py中实现请求响应的函数,在子路由urls.py中为URL绑定函数
网友评论