我试图在我的项目中注册一个用户,但当我尝试注册时,我会得到以下错误:
ValueError: The given username must be set
views.py
def register(request):
if request.method == 'POST':
username = request.POST['username']
email = request.POST['email']
password = request.POST['password']
first_name = request.POST['fname']
last_name = request.POST['lname']
user = User.objects.create_user(username=username, password=password, email=email,
first_name=first_name, last_name=last_name)
user.save()
print('user created')
return redirect("register")
else:
return render(request,'register.html')
正如一个人所说,你应该提供完整的错误和更多的代码,但根据我的猜测,你可能需要这样做:
username = request.POST.get('username')
但是我们需要更多的裁判来了解错误。