我在使用 authenticate () 方法的 django 身份验证系统上出错

I have an error on django athentication system with authenticate () method

我对身份验证 () 方法有疑问,请帮助我。 它 return 对我来说 '' 视图没有 return 一个 httpresponse 。它 return 改为 none。

def registrazione (request):
    if request.method == 'POST':
        form = FormSito(request.POST)
        if form.is_valid():
            username = form.cleaned_data ["username"]
            password = form.cleaned_data ["password"]
            User.objects.create_user (
                username = 'username',
                password = 'password'
            )
            
            user = authenticate (request,User)
        else: 
            form = FormSito()
            context = { form : 'form' }
            return render (request,"registration/form/registrazione.html", context)

错误清楚地说明了这里发生的事情。当 form.is_valid() 为真时,您根本不需要 return 任何东西。

def registrazione (request):
    if request.method == 'POST':
        form = FormSito(request.POST)
        if form.is_valid():
            username = form.cleaned_data ["username"]
            password = form.cleaned_data ["password"]
            User.objects.create_user (
                username = 'username',
                password = 'password'
            )
            
            user = authenticate (request,User)
        else: 
            form = FormSito()
            context = { form : 'form' }
        # you had problem here
        return render (request,"registration/form/registrazione.html", context)