gpt4 book ai didi

python - Google App Engine Python If Else 在 Html 模板中的用法

转载 作者:太空狗 更新时间:2023-10-30 02:00:20 25 4
gpt4 key购买 nike

我正在使用 python 在谷歌应用引擎中创建一个网站。不幸的是,我找不到任何关于我的问题的信息。我必须根据其内容来区分变量。

例如我要发送这样的变量

content = {
'mail':session.get('user_mail',''),
'role':'Admin',
}
render_template(self, 'index.html', content)

如果是“登录”用户或“管理员”用户,我需要此类代码来了解用户类型。

{% if role == 'Ordinary' %}
{{ role }}
{% elif role == 'Admin' %}
{{ role }}
{% endif %}

我该怎么做?

或者您可以向我推荐更好的设计。

谢谢...

最佳答案

django 模板中没有elif。使用这样的东西:

{% if role == 'Login' %}
... stuff
{% else %}{% if role eq 'Admin' %}
... stuff
{% endif %}

或者,使用 ifequal:

{% ifequal role "Login" %}
... stuff
{% else %}{% ifequal role "Admin" %}
... stuff
{% endifequal %}

关于python - Google App Engine Python If Else 在 Html 模板中的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4849224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com