Django Invalid block tag: 'else'

梦想与她 提交于 2019-12-13 20:25:29

问题


Newbie question.

I need to extend to the user template if the user is authenticated otherwise extend the guest template.

I have the following code at the top my page.

{% if request.user.is_authenticated %}
    {% extends 'users/base.html' %}
{% else %}
    {% extends 'guests/base.html' %}
{% endif %}

But then I get the following error:

TemplateSyntaxError at /events/
Invalid block tag: 'else'

If I don't use extends inside the condition then it works. So i'm confuse what is wrong:

{% if request.user.is_authenticated %}
    user
{% else %}
    guest
{% endif %}

来源:https://stackoverflow.com/questions/23789434/django-invalid-block-tag-else

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