How to create Login Form in Django application


Django provides filter() to implement login operation manually, if we want to perform login without using the Django library and models then we can simply use filter().

filter()  will return QuerySet and we can get the size of the query set, if the size will be greater then 0 then it will return

1)  Create




2)  Create design under templates/projectname

<!DOCTYPE html>




 <link rel="stylesheet" type="text/css" href="/static/css/style.css">



 <header><h1>Welcome in FeedBack System Application</h1>


<ul><li><a href="home">Home</a></li><li><a href="about">About</a></li><li><a href="contact">Contact us</a></li><li><a href="service">Service</a></li><li><a href="gallery">Gallary</a></li></ul>




  <h1>New User Register Here</h1>

  <form action="" method="post">

  {% csrf_token %}

    <input type="text" name="txtemail" placeholder="Enter emailid" required="" />


    <input type="text" name="txtpass" placeholder="Enter password" required="" />




    <input type="submit" name="btnsubmit" value="Login" />






  <div class="part">


  <div class="part">


  <div class="part">

         <ul><li><a href=""><img src="/static/img/fb.png" height="30" width="30" /></a></li><li><a href=""><img src="/static/img/insta.png" height="30" width="30" /></a></li><li><a href=""><img src="/static/img/twt.png" height="30" width="30" /></li></li><li><a href=""><img src="/static/img/youtube.png" height="30" width="30" /></li></ul>





3)   write code on to manage the login, logout, and about the method

def logout(request):

   del request.session['uid']

   return redirect("login")

def login(request):

   if request.method=="POST":

      uname = request.POST["txtemail"]

      upass = request.POST["txtpass"]

      s = Register.objects.filter(emailid=uname,password=upass)



         return redirect("about")


         return render(request,"frontdesk/login.html",{"key":"invalid userid and password"})   

   return render(request,"frontdesk/login.html")

def about(request):


  s = Register.objects.all()

  return render(request,"frontdesk/about.html",{"res":s})


  return redirect("login") 

Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)