Im trying to write within my django template a piece that will display text if it is a certain user.
i.e
{{ user }}
{% if user == "bob.smith" %}
<p>Hello</p>
{% endif %}
However Hello never prints even though the output to {{ user }}
is shown as bob.smith.
Any ideas ?
答案 0 :(得分:0)
Django用 unicode 方法代表用户,该方法连接第一个和姓氏(%s.%s) % (first_name, last_name)
。
如果你真的想像你所展示的那样在HTML中进行硬编码那么你最好去用户主键/ id(只需用bob.smith主键或id替换1):
{% if user.pk == 1 %}
<p>Hello</p>
{% endif %}
希望这有帮助。