Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在条件扩展页面中使用djangocms插件吗?_Django_Django Templates_Django Cms - Fatal编程技术网

我可以在条件扩展页面中使用djangocms插件吗?

我可以在条件扩展页面中使用djangocms插件吗?,django,django-templates,django-cms,Django,Django Templates,Django Cms,我在djangocms页面模板的顶部有这个 {% extends request.user.is_authenticated|yesno:"member_template.html,base.html" %} 我的插件无法使用此设置。但如果我这样做 {% extends "member_template.html" %} 我的插件可以工作。有办法解决这个问题吗?我想要有条件的。你能不能把if语句放进去 {% if user.is_authenticated %} {% extends "me

我在djangocms页面模板的顶部有这个

{% extends request.user.is_authenticated|yesno:"member_template.html,base.html" %}
我的插件无法使用此设置。但如果我这样做

{% extends "member_template.html" %}

我的插件可以工作。有办法解决这个问题吗?我想要有条件的。

你能不能把if语句放进去

{% if user.is_authenticated %} {% extends "member_template.html" %}
{% else %} {% extends "base.html" %}
{% endif %}

假设您正在视图中使用渲染

if request.user: base_file = "member_template.html"
else: base_file = base.html
render(request,'my_html.html',
               {'base_file' : base_file})
然后您的extends标记看起来像:

{% extends base_file %}

否,模板中的第一行必须是extend。如果我按照你的建议去做,那就错了。是的,对不起。但是extends后面还需要紧跟着它所扩展的文件,或者是一个计算结果为该文件的变量,所以您需要一个标记,或者将其包含在context中。您能给我举个例子吗?我对此一无所知。@DharienCthaeh你想过这个吗@DharienCthaeh在单独的回答中看到了这个例子,你想过这个吗?