问题描述
我目前正在使用一个使用django-registration和Django CMS的项目。当显示实现django-registration的页面时,我的页面标题不会呈现。
I'm currently working on a project that uses django-registration and Django CMS. When display the pages that implement django-registration my page titles do not render.
目前有< title> {%page_attribute page_title%}< ; / title>
在我所有的模板继承的base.html中。
Currently have <title>{% page_attribute page_title %}</title>
in base.html which all my templates inherit from.
在不使用django注册的页面中,标题显示只是很好,但django注册显示为< title>< / title>
In the pages that do not use django-registration the titles display just fine, but django-registration display as <title></title>
我的网页都是在CMS内创建,其他一切都正确呈现。如果我在模板中明确设置标题,标题将呈现,但我宁愿将其设置在CMS内。
My pages are all created within the CMS and everything else is rendering correctly. If I set the title explicitly within the template, the title will render, but I'd rather have it set within the CMS.
registration_form.html的相关部分是以下:
The relevant portion of registration_form.html is below:
{% extends "base.html" %}
{% load cms_tags %}
{% load i18n %}
{% block "html_headers" %}
<!-- conditional stuff here -->
<link href="/media/css/forms.css" rel="stylesheet" type="text/css" />
{% endblock %}
谢谢!
推荐答案
{%page_attribute%}
模板标签仅适用于CMS页面。当由django-registration控制的视图中,它们不会工作,而是返回一个空字符串(因为Django的模板语言不应该在运行时引发异常)。在django注册使用的模板中,您需要覆盖标题标签。
the {% page_attribute %}
template tag only works on CMS pages. When in views controlled by django-registration, they will not work and rather return an empty string (since Django's template language should never raise exceptions on runtime). In the templates used by django-registration, you need to override the title tag.
因此,我建议您使用< title> {%block title%} {%page_attribute page_title%} {%endblock%}< /标题>
。然后在注册模板中执行类似 {%block title%}注册{%endblock%}
。
Therefore I suggest you use <title>{% block title %}{% page_attribute page_title %}{% endblock %}</title>
in your base template. Then in the registration template do something like {% block title %}Registration{% endblock %}
.
这篇关于Django CMS页面标题不呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!