0

我目前正在关注 Django 教程,我相信我完全遵循了它,但是我收到了这个语法错误。就是说{% endblock %}行不通。不太确定为什么这是不正确的。我正在尝试创建部分视图或模板继承并将其插入base.html

我的错误:

Invalid block tag: 'endblock'
Request Method: GET
Request URL:    http://127.0.0.1:8000/articles/all/
Django Version: 1.6
Exception Type: TemplateSyntaxError
Exception Value:    
Invalid block tag: 'endblock'

Error during template rendering

In template /Users/bradfordli/Development/django-brad/django_test/article/templates/articles.html, error at line 25
Invalid block tag: 'endblock'
15  {% endfor %}
16  {% else %}
17  
18  <p> None to show!</p>
19  
20  {% endif %}
21  
22  </body>
23  </html>
24  
25  {% endblock %}
26

我的文章.html

{% extends "base.html" %} <!-- this templates extends the base.html template -->

(% block content %)

<html>
<body>
<h1>Articles</h1>

{% if articles.count > 0 %}
{% for article in articles %}
<div>
<h2><a href = "/articles/get/{{article.id}}">{{article.title}}</a></h2>
<p>{{article.body|upper}}</p>
</div>
{% endfor %}
{% else %}

<p> None to show!</p>

{% endif %}

</body>
</html>

{% endblock %}

我的 base.html

<!-- Base of every pate in the side-->

<!DOCTYPE html>
<html lang = "en">
<head>
    <title>{% block title %} My Base Template {% endblock %}</title>

    <style type="text/css">
        body {
            text-align: center;
        }

        #page {
            width: 960px;
            text-align: left;
            margin: 10px auto 20px auto;
            background-color: #0c0c0c;
        }

        #sidebar {
            float: left;
            width: 200px;
            border: 1px solid #000;
        }

        #content {
            float: left;
            width: 600px;
            border: 1px solid #f00;
            padding: 10px;
        }

    </style>

</head>

<body>
    <div id = "page">
        <div id = "sidebar">
            <!-- This block of the page is named "sidebar" 
            Also anything between can be substituded by other templates 
            as long as they refer to sidebar as a block within their template
            -->
            {% block sidebar %} 
            <ul>
                <li><a href="/articles/all/"> Articles</a></li>
                <li><a href="/admin/"></a>Admin</li>
            </ul>   
            {% endblock %}
        </div>
        <div id = 'content'>
            <!-- This block of the page is named "content"-->
            {% block content %} This is the content area {% endblock %}     
        </div>
    </div>

</body>
</html>
4

1 回答 1

1

我在这里看不到任何endblock东西:

<title>{% block title %} My Base Template</title>

更改以下内容:

(% block content %)  => {% block content %}
于 2013-11-12T00:33:03.860 回答