在终端中首先连接 sqllite
python manage.py migrate
settings 的设置
LANGUAGE_CODE = ‘zh-hans’ #改语言默认是 en-us
TIME_ZONE = ‘Asia/Shanghai’ #改时区,默认 UTC
3.28的新版将不在是 url, 而是path, 如果需要用正则就是re_path
from django.urls import path, include, re_path
re_path(r’^hello/’, views.hello), #新版本需要用到正则表达式使用re_path()
新建一个views
def temp(request):
return HttpResponse(“
def index(request):
return render(request,‘index.html’) 新建一个文件夹APP,类似于新建一个子项目
终端运行,python manag.py startapp two
新建后,后需第一时间在原App的settings里INSTALLED_APPS 列表里添加这个新项目
这样在two下可以编辑urls, 和views等文件
主App 的urls 添加 re_path(r’^two/’, include(‘two.urls’)), #引入two的app的关联到two 的urls
完成设置。 通过http://127.0.0.1:8000/two/index访问测试
这是映射子项目路由的 关键写法
需要在pycharm中 右键temlates文件夹,将文件夹标记为模板文件夹
同时要在settings中进行注册
‘DIRS’: [base_DIR / ‘templates’]



