Y
Y
Yeldos Adetbekov2015-10-20 16:02:59
Python
Yeldos Adetbekov, 2015-10-20 16:02:59

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("/")

2fc1472038414a3dabb831c584a94669.png
Where the login there should be a field and not a chuzer.
Help me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Shultais, 2015-10-20
@dosya97

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 question

Ask a Question

731 491 924 answers to any question