Python Django CMS–在同一模板中为用户和来宾显示不同的内容

Python Django CMS–在同一模板中为用户和来宾显示不同的内容,python,django,django-templates,django-cms,Python,Django,Django Templates,Django Cms,我想有不同的内容,为用户和客人在我的主页的模板使用Django 1.9和Django CMS 3.3.1 它可以通过根据身份验证条件制作子页面并在祖先中显示相应的内容来完成,但这使得页面结构过于复杂 有没有一种简单的方法可以直接将这些占位符添加到模板中 我试过这个: 但由于我在编辑内容时已通过身份验证,因此无法访问来宾占位符。请尝试以下操作: 我有一些使用Django CMS的经验,但不知道这是否有效。其思想是通过检查相应的请求变量来检查我们是否处于编辑模式。看 @V-Kopio更新: 上面给出

我想有不同的内容,为用户和客人在我的主页的模板使用Django 1.9和Django CMS 3.3.1

它可以通过根据身份验证条件制作子页面并在祖先中显示相应的内容来完成,但这使得页面结构过于复杂

有没有一种简单的方法可以直接将这些占位符添加到模板中

我试过这个:

但由于我在编辑内容时已通过身份验证,因此无法访问来宾占位符。

请尝试以下操作:

我有一些使用Django CMS的经验,但不知道这是否有效。其思想是通过检查相应的请求变量来检查我们是否处于编辑模式。看

@V-Kopio更新:

上面给出的答案在实践中效果很好,但Django警告不要使用复杂的占位符。这可以通过组合if和else块来避免:


你救了我一天。实际的一半已经不见了。但还是非常感谢。
{% 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 %}
{% block content %}
    {% if request.toolbar.build_mode or request.toolbar.edit_mode %}

        {% placeholder "guests" %}
        {% placeholder "authenticated" %}

    {% else %}

        {% if not user.is_authenticated %}
            {% placeholder "guests" %}
        {% endif %}

        {% if user.is_authenticated %}
            {% placeholder "authenticated" %}
        {% endif %}

    {% endif %}

    {% placeholder "content" %}
{% endblock content %}
{% block content %}

    {% if not user.is_authenticated or request.toolbar.build_mode or request.toolbar.edit_mode %}
        {% placeholder "guests" %}
    {% endif %}

    {% if user.is_authenticated %}
        {% placeholder "authenticated" %}
    {% endif %}

    {% placeholder "content" %}
{% endblock content %}