【发布时间】:2016-12-04 03:18:18
【问题描述】:
我希望使用 Django 1.9 和 Django CMS 3.3.1 在我的主页模板中为用户和访客提供不同的内容。
可以通过根据认证条件制作子页面并在祖先中显示相应内容来完成,但这会使页面结构过于复杂。
有没有一种简单的方法可以将这些占位符直接添加到模板?
我试过这个:
{% extends "base.html" %}
{% load cms_tags %}
{% block title %}{% page_attribute "page_title" %}{% endblock title %}
{% block content %}
{% if not user.is_authenticated %}
{% placeholder "guests" %}
{% endif %}
{% if user.is_authenticated %}
{% placeholder "authenticated" %}
{% endif %}
{% placeholder "content" %}
{% endblock content %}
但由于我在编辑内容时已通过身份验证,因此我无法访问 guests 占位符。
【问题讨论】:
标签: python django django-templates django-cms