作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 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/
我是一名优秀的程序员,十分优秀!