Answer the question
In order to leave comments, you need to log in
How to fix invalid request.user output in django?
Good day, when creating authorization, I abandoned the LoginView bicycle, since redefining and remaking it for what I need will take much more time than if I write it myself
To the essence of the problem:
Here are some fields of the model
class User(AbstractUser):
username = models.CharField(max_length=100, null=True, blank=True, unique=True)
login = models.CharField(max_length=100, verbose_name="Логин", blank=False, default="NULL")
password = models.CharField(max_length=100, verbose_name="Пароль", blank=False, default="Null")
from django.views.generic import View
from django.contrib import auth
from myapp.models import User
class Login(View):
def post(self, request):
login = request.POST.get("username", "")
password = request.POST.get("password", "")
login_objects = [login.get("login") for login in User.objects.all().values()]
if login in login_objects:
if User.objects.filter(login = login).values()[0].get("password") == password:
user = auth.authenticate(login=login, password=password)
auth.login(request, user)
try:
return render (request, "page.html")
finally:
return redirect("url_page")
Answer the question
In order to leave comments, you need to log in
Probably, the whole point is that you have not overridden the AUTH_USER_MODEL setting . I propose to dig in this direction, because, if my memory serves me, the user gets into the request object based on exactly that setting.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question