Good afternoon! A little confused in the authorization model of the user from another database.

backends.py class TestAuthenticationBackend(object): def authenticate(self, username=None, password=None): cursor = connection.cursor() cursor.execute("select * from system_accounts where is_deleted=0 and \ login='{0}' and password='{1}'".format(username,password)) user = cursor.fetchone() return user views.py def login_view(request): if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username,password=password) return auth_views.login(request, 'accounts/login.html') settings.py AUTHENTICATION_BACKENDS = ('accounts.backends.TestAuthenticationBackend',) 

As a result, I get the error:

AttributeError: 'tuple' object has no attribute 'backend'

    1 answer 1

    No need to climb into the database directly. Use ORM.

    • There is no desire to describe the table in the models, I immediately wanted to direct. - avdoshkin
    • therefore does not work - ravli
    • It is clear, then I will fix it now. - avdoshkin
    • This error is fixed, how to record now the session is using the function if user is not None: login (request, user) here is such an error: octm fields: last_login - avdoshkin
    • Your model must provide some kind of interface for the user to work: docs.djangoproject.com/en/1.5/topics/auth/customizing ... ... - ravli 1:59 pm