When you start a Django project called "myproject", within that project you get a folder also called "myproject". Should I put my base.html (which includes links to CDNs like Bootstrap that are used by all my apps) in a folder called "myproject" within a templates folder within the "myproject" folder? In other words, should I put the base.html in myproject/templates/myproject and then place at the top of each HTML page in every app:
当你启动名为“myproject”的Django项目时,在该项目中你会得到一个名为“myproject”的文件夹。我应该将我的base.html(包括我的所有应用程序使用的Bootstrap等CDN的链接)放在“myproject”文件夹中的模板文件夹中名为“myproject”的文件夹中吗?换句话说,我应该将base.html放在myproject / templates / myproject中,然后放在每个应用程序的每个HTML页面的顶部:
{% extends 'myproject/templates/myproject/base.html %}
?
{%extends'myproject / templates / myproject / base.html%}?
Alternatively, do I place a base.html in each app and extend like: {% extends 'myapp/templates/myapp/base.html %}
? Thank you.
或者,我是否在每个应用中放置一个base.html并扩展为:{%extends'myapp / templates / myapp / base.html%}?谢谢。
1 个解决方案
#1
0
keep your base.html in myapp/templates/base.html
将您的base.html保存在myapp / templates / base.html中
and you can extend it using,
你可以用它扩展它,
{% extends 'base.html' %} on each HTML template..
but ensure your TEMPLATE_DIRS in settings.py
但请确保您在settings.py中使用TEMPLATE_DIRS
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
.....
}
]
django will take of template dir path automatically...
django将自动采用模板dir路径...
#1
0
keep your base.html in myapp/templates/base.html
将您的base.html保存在myapp / templates / base.html中
and you can extend it using,
你可以用它扩展它,
{% extends 'base.html' %} on each HTML template..
but ensure your TEMPLATE_DIRS in settings.py
但请确保您在settings.py中使用TEMPLATE_DIRS
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
.....
}
]
django will take of template dir path automatically...
django将自动采用模板dir路径...