Django CMS Page Title Doesn't Render

大城市里の小女人 提交于 2020-01-01 05:00:06

问题


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.

Currently have <title>{% page_attribute page_title %}</title> in base.html which all my templates inherit from.

In the pages that do not use django-registration the titles display just fine, but django-registration display as <title></title>

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.

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 %}

Thanks!


回答1:


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.

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 %}.



来源:https://stackoverflow.com/questions/10077543/django-cms-page-title-doesnt-render

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!