Ich lese viele Themen zu diesem Problem und das Problem ist immer da. Wenn ich mein Anmeldeformular einreiche, gibt die Authentifizierungsfunktion() None zurück. Ich habe die Funktion set_password() für die Registrierung verwendet und es ändert nichts.Django - authenticate() zurück Keine
Hier ist mein Code (auch here):
from django.contrib.auth.models import User
from django.shortcuts import render
from forms import LoginForm, RegistrationForm
from django.contrib import auth
def login(request):
state = 0 # 0 = initialisation/1 = OK/2 = BAD_PW
form = LoginForm()
if request.method == 'POST':
error = False
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data["email"]
password = form.cleaned_data["password"]
user = auth.authenticate(email=email,
password=password)
if user:
auth.login(request, user)
state = 1
else:
state = 2
print "login state " + str(state)
else:
form = LoginForm()
return render(request, "birneo/login.html", locals())
def register(request):
state = 0
form = RegistrationForm()
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User()
user.username = form.cleaned_data['username']
user.email = form.cleaned_data['email']
user.set_password(form.cleaned_data['password'])
user.save()
state = 1
form = RegistrationForm()
else:
form = RegistrationForm()
return render(request, "birneo/register.html", locals())