user authentication

hi, anyone help me with user authentication, i am unable to authenticate a user after signup, it let me login in admin site but as a normal user i am unable to login in website, sorry for the code i am unable to proper indent here.

    if request.method == "POST":
        fm = AuthenticationForm(request=request, data=request.POST)
        if fm.is_valid():
            username = fm.cleaned_data.get('username')
            password = fm.cleaned_data.get('password')
            user = authenticate(request,username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect('/jobseekersprofile/')
    else:
        fm = AuthenticationForm()
    return render(request, 'jobglobel/userlogin.html', {'form': fm})```

To indent the code here you must use the backtick ` in the beggining and end of the line.
For multilines use 3 backticks.

done thanx, do you have any idea what problem could be ?, i am unable to authenticate any normal user in website, when do login in admin site it allows to do login in admin site.

Now that we had properly formatted code, it’s required some more information about what is happening.

Are you seeing any errors on the console, do you receive any errors on the page?

We will need to see the complete view, and the template you are using (userlogin.html).

no i am not facing an any error, it just render me same login page, after putting right credentials.
Here is Template which i am using

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jobseekers Login</title>
    <link rel="stylesheet" type="text/css" href="{% static 'jobglobel/css/userlogin.css' %}">
    <link rel="stylesheet" type="text/css" href="{% static 'jobglobel/css/font.css' %}">
    <link rel="shortcur icon" type="image/png" href="{% static 'jobglobel/images/worldwide.png' %}">
</head>

<body>
    <div class="div00">
        <nav>
            <h2>WelCome To</h2>
            <a href="{% url 'home' %}"><img class="img1" src="{% static 'jobglobel/images/worldwide.png' %}" alt=""></a>
            <a class="divjoba1" href="{% url 'home' %}">JobGlobeL</a>
            <p class="navp">WorldWide</p>
            <p class="navp1">Not Registered Yet?</p>
            <a href="{% url 'usersignup' %}"><button class="btn1">SIGNUP NOW</button></a>
            <p class="navp2">Here.</p>
        </nav>
    </div>
    <div class="div1">
        <div class="div11">
            <p>JobSeeker's & Recruiters Login</p>
            <form class="formlogin" action="" method="POST" novalidate>
                {% csrf_token %}
                <div class="userdiv" >
                    <span class="sp" >* </span>{{form.username.label}} <br> {{form.username}} <span class="error" >{{form.username.errors|striptags}}</span>
                </div> 
                <div class="userpass">
                    <span class="sp" >* </span>{{form.password.label}} <br> {{form.password}} <span class="error" >{{form.password.errors|striptags}}</span> <br>
                </div>
                <input class="submitbtn" type="submit" value="LOGIN">
            </form>
        </div>
    </div>
</body>

</html>```

We still need to see the complete view, and the form.

from django.shortcuts import redirect, render
from .forms import jobglobeluserform
from .models import jobglobeluser
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate,login,logout,views
from django.contrib.auth.decorators import login_required


def userlogin(request):
    if request.method == "POST":
        fm = AuthenticationForm(request=request, data=request.POST)
        if fm.is_valid():
            username = fm.cleaned_data.get('username')
            password = fm.cleaned_data.get('password')
            user = authenticate(request,username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect('/jobseekersprofile/')
    else:
        fm = AuthenticationForm()
    return render(request, 'jobglobel/userlogin.html', {'form': fm})```


FORM I HAVE USED INBUILT FORM DJANGO ' AuthenticationForm()' As you can see in views.py 


FOR Template I have Posted Earlier. You Can check it above.






hiii, have you find any problem?

I would use the Django shell to try that authenticate function call with the username and password that you are trying, to verify that the password is valid.

password is same as i kept while creating user for testing purpose., as normal user it is not allowing me to do login, but if i create superuser and do login in admin site, it is working.

How did you specifically create the user and assign the password?

using model form by validing it in forms.py(built in method ), not created custom user model.

Show me your view that creates your user.

from django.shortcuts import redirect, render
from .forms import jobglobeluserform
from .models import user
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate, login, logout, views
from django.contrib.auth.decorators import login_required

def userregistration(request):
    if request.method == 'POST':
        fm = jobglobeluserform(request.POST, request.FILES)
        if fm.is_valid():
            useris = fm.cleaned_data.get('useris')
            firstName = fm.cleaned_data.get('FirstName')
            lastname = fm.cleaned_data.get('LastName')
            username = fm.cleaned_data.get('username')
            email = fm.cleaned_data.get('email')
            code = fm.cleaned_data.get('code')
            mobile = fm.cleaned_data.get('mobile')
            country = fm.cleaned_data.get('country')
            state = fm.cleaned_data.get('state')
            city = fm.cleaned_data.get('city')
            gender = fm.cleaned_data.get('Gender')
            password = fm.cleaned_data.get('password')
            rpassword = fm.cleaned_data.get('rpassword')
            resume = fm.cleaned_data.get('resume')
            reg = user(useris=useris, FirstName=firstName, LastName=lastname, username=username, email=email, code=code, mobile=mobile,
                                country=country, state=state, city=city, Gender=gender, password=password, rpassword=rpassword,
                                resume=resume)
            reg.save()
            global val

            def val():
                return firstName
            global val2

            def val2():
                return lastname
            return redirect('/success/')
    else:
        fm = jobglobeluserform()
    return render(request, 'jobglobel/usersignup.html', {'form': fm})

What is this user(... function? (Please answer with the actual code, not a description of it.)

class of model.py file which i have created for saving users in my website

Please show the code for this model.


class user(models.Model):
    joined_on = models.DateTimeField(auto_now_add=True)
    useris = models.CharField(max_length=30,null=True)
    FirstName = models.CharField(max_length=20)
    LastName = models.CharField(max_length=20)
    username = models.CharField(max_length=100)
    email = models.EmailField(unique=True,max_length=150)
    code = models.CharField(max_length=20)
    mobile = models.CharField(max_length=13)
    country = models.CharField(max_length=30)
    state = models.CharField(max_length=30)
    city = models.CharField(max_length=30)
    Gender = models.CharField(max_length=20)
    password = models.CharField(max_length=20)
    rpassword = models.CharField(max_length=20)
    resume = models.FileField(upload_to='docs/')

Why do you think the authenticate function is going to check this model instead of the system-defined User model?