当我运行这个时:
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login as auth_login
def login(request):
if request.user.is_authenticated():
username = request.user.username
else:
username = None
return render (request, 'login_success.html', {'username': username})
我收到此错误:
TypeError at /login/success/
'bool' object is not callable
这是我的 html:
{% include 'base.html' %}
<text align="center">Sup {{ username }}, you're logged in!</text>
该错误是什么意思,我该如何解决?
答案 0 :(得分:2)
is_authenticated
是一个属性,你只需要去掉括号
https://docs.djangoproject.com/en/3.1/ref/contrib/auth/#attributes