1.在工程中创建模板目录templates。
2.在项目的settings.py中修改template配置:
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', # 模板引擎 'DIRS': [os.path.join(BASE_DIR, 'templates')], # 这里修改 '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', ], }, }, ]
3.后续templates文件夹中创建html文件,然后在视图函数中可以直接渲染.
4.参考: https://docs.djangoproject.com/en/3.2/ref/templates/api/#overview
查看更多关于Django 静态文件模板路径配置的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did125858