【问题标题】:Django Template Language Shows Up In WebpageDjango 模板语言出现在网页中
【发布时间】:2021-05-28 17:48:56
【问题描述】:

当网页在测试服务器上运行时,会显示我的 Django 模板语言标签。有谁知道为什么会发生这种情况? (网页上的其他所有内容都正常显示,标签甚至都在发挥作用。我只是不知道为什么会有文字。

页面的html:

 <% extends "base.html" %> 


<% block page_title %> Challenges <% endblock %>

<% block content %> 
<ul> 
    {% for month in months%}
    <li> <a href="{% url 'month-challenge' month %}">{{month|title}} </a></li>

    
        {% endfor %}
    </ul>
    <% endblock %> 



The template that the page is inheriting from: 

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block page_title %} {% endblock %}</title> 
</head>
<body>
    {% block content %}

    {% endblock %}
    
</body>
</html>

What the output looks like:

我在这里查看过类似的帖子,但这些修复似乎都不适用于此处(直接打开 html 文档,在 { 和 % 之间留一个空格等。

【问题讨论】:

  • 非常仔细地查看你的html。您至少有 4 行包含 &lt;%%&gt; 而不是 {%%}。这些是显示在您的浏览器中的行。
  • 哦,哇,非常感谢你,你合法地为我节省了大约 3 年的时间,让我注意到这一点!

标签: django django-templates


【解决方案1】:

模板标签被包裹在<b>{%</b> … <b>%}</b>中,而不是&lt;% … %&gt;

因此,您可以使用:

{% extends "base.html" %} 

{% block page_title %} Challenges {% endblock %}

{% block content %} 
  <ul> 
    {% for month in months%}
    <li> <a href="{% url 'month-challenge' month %}">{{month|title}} </a></li>

    
    {% endfor %}
  </ul>
{% endblock %}

【讨论】:

    猜你喜欢
    • 2019-08-01
    • 2012-11-29
    • 2020-04-24
    • 2018-02-22
    • 2017-01-07
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多