我为我正在进行的项目制作了自定义用户模型,并且我尝试使用is_authenticated
来允许人们访问其个人资料并进行更改。但是,它说没有WSGI对象。我不知道为什么会这样,我想要一些帮助!
from django.shortcuts import render
from django.contrib.auth import get_user_model
from userstest.models import CustomUser
from userstest.admin import CustomUserCreationForm, CustomUserChangeForm
u = get_user_model()
def index(request):
form = CustomUserCreationForm()
if request.u.is_authenticated():
a = request.u
form2 = CustomUserChangeForm(instance=a)
return render(request, "index.html", {'form2': form2})
答案 0 :(得分:1)
如错误所述,请求对象上没有“u”属性。只需将request.u
更改为request.user
。
def index(request):
form = CustomUserCreationForm()
if request.user.is_authenticated():
form2 = CustomUserChangeForm(instance=request.user)
return render(request, "index.html", {'form2': form2})