S
S
Sergey Nizhny Novgorod2017-03-23 03:18:40
Django
Sergey Nizhny Novgorod, 2017-03-23 03:18:40

Why is the user authorization in django not going through?

Hello.
I want to login random users -

if request.user.is_anonymous():

        usertag = random.randint(10000, 99999)
        username = "visitor"+str(usertag)
        password = "Visitor"+str(usertag)
        email = username + '@' + str(usertag) + '.ru'
        user_obj=User(username=username, password=password, email=email)
        user_obj.save()

        user = auth.authenticate(username=user_obj.username, password=user_obj.password)
        auth.login(request, user)

        current_user = request.user
       
        if request.POST:
            so on...

Here, when running this code, an error is thrown:
'AnonymousUser' object has no attribute '_meta'
If you look at the data, it swears at auth.login(request, user) - since user = None. I don't seem to be making any mistakes, why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iegor, 2017-03-23
@Terras

you are making a mistake stackoverflow.com/questions/10372877/how-to-create...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question