Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 Before Login first create a table using Registration and do registration work first:-


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 urls.py

 path('about',views.about,name='about'),

 path('login',views.login,name='login'),

 path('logout',views.logout,name='logout'),




2)  Create design under templates/projectname



<!DOCTYPE html>

<html>

<head>

 <title></title>

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

</head>

<body>

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

 <hr>


<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>

</header>

 <section>

  <center>

  <h1>New User Register Here</h1>

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

  {% csrf_token %}

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

    <br><br>

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

 

  

    <br><br>

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



  </form>

  {{key}}



</center>

</section>

 <footer>

  <div class="part">


  </div>

  <div class="part">


  </div>

  <div class="part">

         <ul><li><a href="http://facebook.com/shivaconceptsolution"><img src="/static/img/fb.png" height="30" width="30" /></a></li><li><a href="http://instagram.com/shivaconceptsolution"><img src="/static/img/insta.png" height="30" width="30" /></a></li><li><a href="http://twitter.com/shivaconceptsolution"><img src="/static/img/twt.png" height="30" width="30" /></li></li><li><a href="http://youtube.com/shivaconceptsolution"><img src="/static/img/youtube.png" height="30" width="30" /></li></ul>

  </div>

 </footer>


</body>

</html>



3)   write code on views.py 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)

      if(s.count()>0):

         request.session['uid']=uname

         return redirect("about")

      else:

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

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


def about(request):

 if(request.session.has_key('uid')):

  s = Register.objects.all()

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

 else:

  return redirect("login") 

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post