Having trouble with user.is_authenticated in django template

后端 未结 2 1375
粉色の甜心
粉色の甜心 2020-12-05 17:11

Sorry if you tried helping me when I asked this earlier. Had to delete that question because I wasn\'t being allowed to edit additional information for some reason.

2条回答
  •  遥遥无期
    2020-12-05 17:57

    Be aware that since Django 1.10 the is_authenticated is decorated with @property and it behaviour differs.

    For UNAUTHENTICATED user calling {{user.is_authenticated}} results:

    CallableBool(True) (when on Django < 1.10 it was True)

    For AUTHENTICATED user calling {{user.is_authenticated}} results:

    CallableBool(False) (when on Django < 1.10 it was False)

    If you need to pass e.g to your javascript value like true or falseyou can do it with applying filter |yesno:"true,false"

    
    

提交回复
热议问题