die*_*usu 1 django django-templates
Django 1.11.3
我有一个模板不存在错误,据我所知我已经正确设置了我的模板目录。Fleetdb是我在项目中拥有的应用程序,具有以下目录结构:
+ fleetdb
+templates
+fleetdb
-index.html
-base.html
(other html pages)
Run Code Online (Sandbox Code Playgroud)
一切正常,直到我尝试在索引内尝试{%extended'base.html'%}为止,如下所示:
{% extends 'base.html' %}
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'fleetdb/lists.css' %}" />
{% if vehicles_list %}
<ul>
{% for vehicle in vehicles_list %}
<li><a href="{% url 'fleetdb:detail' vehicle.id %}">{{ vehicle.unit }} {{ vehicle.make }} {{ vehicle.vmodel }} {{vehicle.color}}</a></li>
</ul>
{% endfor %}
{% else %}
<p>No Vehicles are available.</p>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
在我的settings.py中,我有一条print(TEMPLATES)语句,似乎所有内容都在正确的区域中,但是找不到base.html。在pastebin上跟踪:https : //pastebin.com/raw/MQDAip64
附加问题:如何从另一个应用程序继承模板,就像url标签在哪里{% url 'fleetdb:detail' }?
试试看
{% extends 'fleetdb/base.html' %}
Run Code Online (Sandbox Code Playgroud)
Django templates默认情况下在子目录下查找模板。您已将您的fleetdb文件保存在templates目录下的文件夹下。
建议:如果要对多个应用程序使用通用模板,则将其放在templates根项目文件夹中的目录下。
+project_folder
+app1
+templates
-----
+app2
+templates
-----
+templates
-your-common-templates
-here-
Run Code Online (Sandbox Code Playgroud)
然后,您可以从项目中的任何应用访问它们。
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |