【问题标题】:How to make Django template recognize load tag upon inheriting from base template如何使 Django 模板在从基本模板继承时识别加载标签
【发布时间】:2015-10-14 07:38:42
【问题描述】:

我有以下 base.html

{% load static from staticfiles %}
<html>
   <title>COOL| {% block title %} Sometitle {% endblock %}</title>
<body>

   <!--- BEGIN INSERT CONTENT FOR OTHER PAGE  HERE-->
   {% block 'body' %}
   {% endblock %}

我有 somefile.html 被上面的包裹。

{% extends 'base.html'%}
{% block title %} Contact {% endblock %}
{% block 'body' %}

 <h1> <a href="{%static "files/somefile.csv" %}">CSV</a> </h1>

{% endblock %}

我得到的信息是这样的:

Invalid block tag: 'static', expected 'endblock'

我预计somefile.html 将从base.html 继承{% load static from staticfiles %}。但事实并非如此。正确的做法是什么?

【问题讨论】:

    标签: python html django templates


    【解决方案1】:

    您应该在每个模板中加载标签。

    【讨论】:

    • 我知道这一点,但我认为 Django 使用DRY 概念?
    • @pdubois 好吧,这是 Django 核心团队的问题:)
    • @pdubois 不要将 DRY 与健全性和可维护性混为一谈,大型项目可能有多个自定义标签,而且并非所有标签都需要在每个模板中处理。
    猜你喜欢
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 2015-11-30
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多