【问题标题】:TemplateDoesNotExist at /website/, extended templateTemplateDoesNotExist at /website/,扩展模板
【发布时间】:2013-05-16 02:39:18
【问题描述】:

对不起,如果我的问题写得不好或其他什么,这是我第一次在这里发帖。 所以,我正在尝试 Django 并尝试使用 Django 的通用模板。我创建了一个名为“layout.html”的父模板。 它有三个块,然后我创建了一个从这个“layout.html”扩展的子,检查文件:

layout.html:

<!DOCTYPE html>
<head>
    <link rel="stylesheet" href="style.css" />
    <title>{% block title %}Bleh bleh{% endblock %}</title>
</head>

等等……

index.html:

{% extends "layout.html" %}

{% block title %} My amazing index !!!{% endblock %}

等等……

这两个文件在同一个文件夹中。但是,这是我的错误:

TemplateDoesNotExist at /rubriques/

(是的,rubriques 是我的命名空间)

这是一个错误示例:

Request URL:    http://127.0.0.1:8000/rubriques/
Django Version:     1.5.1
Exception Type:     TemplateDoesNotExist
Exception Value:    

layout.html

Exception Location:     /home/thomas/.virtualenvs/site/local/lib/python2.7/site-packages/django/template/loader.py in find_template, line 139
Python Executable:  /home/thomas/.virtualenvs/site/bin/python
Python Version:     2.7.4


Error during template rendering

In template /home/thomas/projets/siteonglets/rubriques/templates/rubriques/index.html, error at line 1

希望有人可以帮助我,我真的不明白错误来自哪里!

【问题讨论】:

  • 你能发布你的views.py吗?还有settings.py 中的TEMPLATE_DIRS 设置。在您的 index.html 模板 {% extends 'rubriques/layout.html' %} 中可能会纠正该问题
  • 问题出在 TEMPLATE_DIRS 中。感谢您的帮助!

标签: django templates django-templates extends


【解决方案1】:

您需要在 settings.py 中更改 TEMPLATES_DIR。

这样 django 就会知道模板在哪里。

【讨论】:

  • 嘿嘿,这么简单?非常感谢,没有你我找不到。它正在工作!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-27
  • 2020-06-20
  • 2018-09-29
  • 2015-03-01
  • 2019-06-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多