Click here to Skip to main content
15,396,950 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My login page needs a remember me checkbox so that it doesnot need to login with password again.I have the html code for it but django code shows error.Can anyone help me to find the code.

What I have tried:

Python
def adminlogin(request):                                                                                                        
    if request.method=='POST':                                                                                                                                                
          username=request.POST.get('name')                                                                            
          password=request.POST.get('psw')                                                    
          try:                                                                                                             
             remember = request.POST['checkbox']                                                                               
             if remember:                                                                                       
                 settings.SESSION_EXPIRE_AT_BROWSER_CLOSE = False                                         
         except:                                                                                              
            is_private = False                                                                                         
            settings.SESSION_EXPIRE_AT_BROWSER_CLOSE = True                                                     
            if username=="admin@gmail.com" and password=="admin":                                            
              return render(request,'dashboard.html',{'username':username})                                                
            else:                                                                      
              messages.info(request," Invalid Email Address or Password")
    return render(request,'log.html')
return render(request,'log.html')




html
HTML
{% csrf_token %}
    
            <div class="container">                
              {% for message in messages %}
               <div class="alert alert-warning alert-dismissible fade show">
                  {{ message }}
                  
                </div>
              {% endfor %}
            </div>
            <div class="form-group">
              Email Address
              
            </div>
            <div class="form-group">
              Password
              
            </div>
            <div class="checkbox">
              
                 Remember
                me
              
            </div>
            <br>
            <div class="form-group mb-0">
              Login
            </div>
Posted
Updated 9-May-22 6:00am
v12
Comments
Richard MacCutchan 9-May-22 7:18am
   
What error, and where does it occur?
Member 15629421 9-May-22 7:25am
   
It is not working
Richard MacCutchan 9-May-22 7:26am
   
What does that mean?
Member 15629421 9-May-22 7:45am
   
The remeber me checkboxfunction is not working

1 solution

You need to set expiry on session via request.session.set_expiry(value)[^] when checkbox is clicked after user logs in. Hope this helps.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900