4

我在我的项目中使用了Django 套装。Django 套装带有一个默认页脚,我想更改或删除它。根据文档上的说明:

您必须扩展 base_site.html 模板来自定义页脚链接、版权文本或添加额外的 JS/CSS 文件。示例文件可在 github 上找到。

将自定义的 base_site.html 模板文件复制到项目的主应用程序 template/admin/ 目录,然后取消注释并编辑要扩展的块。

但是当我这样做时,每当我取消注释他们的一个块时,我都会遇到以下错误:

Exception Type: TemplateSyntaxError

Exception Value:Could not parse the remainder: '% block footer_links %' from '% block footer_links %'

知道为什么会发生这种情况,我该如何解决?

base_site.html:

{% extends "admin/base.html" %}
{% load admin_static %}

{# Additional <head> content here, some extra meta tags or favicon #}
{#{% block extrahead %}#}
{#{% endblock %}#}


{# Additional CSS includes #}
{#{% block extrastyle %}#}
{#  <link rel="stylesheet" type="text/css" href="{% static 'css/my_project.css' %}" media="all">#}
{#{% endblock %}#}


{# Additional JS files in footer, right before </body> #}
{#{% block extrajs %}#}
{#  <script type="text/javascript" src="{% static 'js/my_project.js' %}"></script>#}
{#{% endblock %}#}


{ Footer links (left side) }
{{% block footer_links %}}
{{% endblock %}}

{# Additional header content like notifications or language switcher #}
{#{% block header_content %}#}
{#    {{ block.super }}#}
{#    <div class="header-content">#}
{#        <!-- First icon column -->#}
{#        <div class="header-column icon">#}
{#            <i class="icon-home"></i><br>#}
{#            <i class="icon-cog"></i>#}
{#        </div>#}
{#        <div class="header-column" style="margin-right: 20px">#}
{#            <a href="/" class="grey">Front-end</a><br>#}
{#            <a href="" class="grey">One more link</a>#}
{#        </div>#}
{#        <!-- Second icon column -->#}
{#        <div class="header-column icon">#}
{#            <i class="icon-comment"></i>#}
{#        </div>#}
{#        <div class="header-column">#}
{#            <a href="" class="grey">5 new messages</a>#}
{#        </div>#}
{#    </div>#}
{#{% endblock %}#}

{ Footer branding name (center) }
{{% block footer_branding %}}
{{% endblock %}}


{ Footer copyright (right side) }
{{% block copyright %}}
{  Copyright &copy; 2013 Client<br>Developed by <a href="http://yoursite.com" target="_blank">YourName</a> }
{{% endblock %}}
4

1 回答 1

1

你把 Django 模板的语法弄错了。这是取消注释文件页脚部分的正确方法:

{# Footer copyright (right side) #}
{% block copyright %}
  Copyright &copy; 2013 Client<br>Developed by <a href="http://yoursite.com" target="_blank">YourName</a> 
{% endblock %}

由于这些错误存在于整个文件中,请使用base_site.html的新副本

于 2014-01-16T13:22:40.027 回答