Answer the question
In order to leave comments, you need to log in
How to create a custom registration and authorization form?
I want a separate plate of users. And so that you can use built-in functions and procedures (login(), logout()), etc.
Before encountering an authorization problem, registration was fine, but how I connected some adjustments
#settings.py
AUTH_USER_MODEL = 'auth.User'
class User(models.Model):
#login=models.CharField(max_length=100,default='') Так было
login = models.ForeignKey(settings.AUTH_USER_MODEL)
password = models.CharField(max_length=100)
class User(models.Model):
def login(request):
if request.method == 'POST' : #and form.is_valid()
login = request.POST['login']
password = request.POST['password']
user = auth.authenticate(username=login, password=password)
print(user)
if user is not None and user.is_active:
# Правильный пароль и пользователь "активен"
auth.login(request, user)
# Перенаправление на "правильную" страницу
return HttpResponseRedirect("/now/")
else:
# Отображение страницы с ошибкой
return HttpResponseRedirect("/")
Answer the question
In order to leave comments, you need to log in
You added a ForeignKey to yourself, so you have a list there, not a field.
you don't have to do that
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question