为什么user.is_superuser在Django模板中返回字符串?

问题描述 投票:1回答:1

你好,我正在使用一个模板,在该模板中,我要显示或隐藏html块,具体取决于用户是否为superUser。代码如下:

<h1> What user.is_superuser returns: {{ user.is_superuser }}</h1>
{% if user.is_superuser %}
        <h1>Superuser</h1>
{% else %}
        <h1>Mindundi</h1>
{% endif %}

想法是向超级用户显示“超级用户”,否则向“ mMindundi”显示。

但是这是我得到的输出:

enter image description here

我一直在拔头发,找不到解决方法。我知道问题出在“”“”“是字符串而不是int,所以所有内容都解析为True ...为什么会发生???我知道一个修复程序会将其解析为int ...,但我想尽可能以其他方式修复它。

供参考,我正在使用这些软件包:

asgiref==3.2.3
certifi==2019.6.16
chardet==3.0.4
defusedxml==0.6.0
Django==2.2.3
django-markdownx==2.0.28
django-model-utils==3.2.0
docxtpl==0.6.3
idna==2.8
Jinja2==2.10.1
lxml==4.3.4
Markdown==3.1.1
MarkupSafe==1.1.1
oauthlib==3.0.2
Pillow==6.1.0
PyJWT==1.7.1
python-docx==0.8.7
python-social-auth==0.3.6
python3-openid==3.1.0
pytz==2019.1
requests==2.22.0
requests-oauthlib==1.2.0
six==1.12.0
social-auth-app-django==3.1.0
social-auth-core==3.2.0
sqlparse==0.3.0
urllib3==1.25.3
xlrd==1.2.0
python django django-templates python-social-auth
1个回答
0
投票

我发现了问题所在。今年夏天,我进行了手动迁移,修复了一些无法自动迁移的表。在过程中的某个地方,我修改了表auth_user,将某些列从整数更改为文本,一经替换,一切便开始按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.