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

标签 django django-templates django-cms

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

{% extends request.user.is_authenticated|yesno:"member_template.html,base.html" %}

我的插件无法使用此设置。但如果我这样做

{% extends "member_template.html" %}

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

最佳答案

假设您在 View 中使用渲染。

if request.user: base_file = "member_template.html"
else: base_file = base.html
render(request,'my_html.html',
               {'base_file' : base_file})

然后你的扩展标签看起来像:

{% extends base_file %}

关于django - 我可以在条件扩展页面中使用 djangocms 插件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38546110/

相关文章:

django - “经理”对象不可调用

django - 如何使用 "reverse"或等效项来引用 Hook 到 DjangoCMS 的 url?

每种语言的 django cms 权限

python - 在 Django 模型字段中存储位置历史记录

python - 在 Django get_object_or_404 中选择特定字段

python - 如何在 Django 中添加 decimal.Decimal 值?

python - 有没有办法仅在屏幕具有一定尺寸时应用 django 过滤器?

jquery - Django:单击按钮加载另一个模板

Django - 简单的自定义模板标签示例

python-3.x - 具有自定义用户模型的 Django-cms : LookupError: Model 'accounts.CustomUser' not registered