栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Django模板文件夹

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Django模板文件夹

你设置好

TEMPLATE_DIRS
settings.py
吗?检查并确保使用绝对路径正确设置了它。这是我确保正确设置的方式:

settings.pyPROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))TEMPLATE_DIRS = (    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".    # Always use forward slashes, even on Windows.    # Don't forget to use absolute paths, not relative paths.    os.path.join(PROJECT_ROOT, 'templates').replace('\','/'),)# List of callables that know how to import templates from various sources.TEMPLATE_LOADERS = (    'django.template.loaders.filesystem.Loader',    'django.template.loaders.app_directories.Loader',#     'django.template.loaders.eggs.Loader',)

这样,我

templates
在项目根目录中有一个用于非应用程序模板的
templates/appname
文件夹,每个应用程序内部都有一个文件夹。

如果要使用根模板文件夹中的模板

'base.html'
,则只需输入模板名称,例如,如果要使用应用程序模板,则使用
'appname/base.html'

资料夹结构:

project/  appname/    templates/       appname/  <-- another folder with app name so 'appname/base.html' is from here        base.html    views.py    ...  templates/    <-- root template folder so 'base.html' is from here    base.html  settings.py  views.py  ...


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391519.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号