Home > Enterprise >  how to use django authentication
how to use django authentication

Time:10-24

views.py

from django.contrib.auth import authenticate 
def loginf(request):
    username = "ph"
    password = "mypassword"
    user = authenticate(username=username, password=password)
    if user is not None:
        print(user)
    else:
        print("not  found") 

return render(request,'myapp/login.html',) 

urls.py

from django.contrib import admin
from django.urls import path
from django.urls.conf import include
from . import views

urlpatterns = [
    
    path('',views.Home.as_view(),name='index'),
    path('signup/',views.SignUpView.as_view(),name='signup'),
    path('login/',views.loginf, name ='login')

    
]

it always return "not found". my username and password are valid, i have double checked username and password, and tried with many users, what i am doing wrong. password saved in database in pbkdf2_sha256 algorithm, how do i authenticate.

CodePudding user response:

You may try replacing:

user = authenticate(username=username, password=password)

with

user = authenticate(request, username=username, password=password)
  • Related