如何在Django中的模板中访问用户详细信息

时间:2020-05-30 16:07:40

标签: django django-templates

我想检查登录的用户是医生还是患者,我尝试了以下方法来检查该东西,但没有成功可以帮助我。

model.py

forms.py

index.html

output

或此错误是什么意思:

Could not parse the remainder: '=='Doctor'' from 'user.user_type=='Doctor''

2 个答案:

答案 0 :(得分:0)

确保==周围有空格。应该是user.user_type == 'Doctor'而不是user.user_type=='Doctor'

好像您在index.html中也有错字。

user.user_type=='Pateint'更改为user.user_type == 'Patient'。请注意==周围的空格。

答案 1 :(得分:0)

使用this,因为制表符是字符串形式的%s

user.user_type == 'Doctor'

user.user_type == 'Patient'