Django 5.0 login failing using admin as well as django.contrib.authLoginView and authenticate()

100 Views Asked by At

I have a problem in Django regarding logging my users in.

I have created some users using the python manage.py makesuperuser.

However, when trying to log one of them in it fails. This holds true for logging in to the admin page as well as my own login page:

# I am using the django.contrib.auth.LoginView here, passing my own template
urlpatterns = [
path("auth/login/",
         LoginView.as_view(template_name="login.html"),
         name="login"),
]

With the following html:

<h2>Login</h2>

<form method="POST">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Login">
</form>

I have also tried using the django.contrib.auth.authenticate method, but it returns None when passing seemingly valid parameters for debugging purposes.

def dashboard(request):
    print(type(authenticate(request, username = "user3", password = "user3_password")))
    return render(request, "dashboard.html")
# Prints nonetype

If it is of any help, the code is inside Onedrive and when hosted on another computer it runs fine. I am using a python virtual environment with Django 5.0 installed. Any help would be appreciated.

**EDIT: ** I am able to login with users that were created now on this device, but not earlier on the other. The database is synced however and getting all users through User.objects.all() returns all entries.

0

There are 0 best solutions below