if request.method=="POST":
username=request.POST['username']
password=request.POST['password']
to
if request.method=="POST":
username=request.POST.get['username']
password=request.POST.get['password']
On Friday, November 27, 2020 at 1:57:37 AM UTC+8 vamshi...@gmail.com wrote:
Hello , am new to Django and i created a login page ,but unable to get login , please help me to solve this , thank you in advanceviews.py :===========from django.views import *from django.shortcuts import render, redirectfrom django.http import HttpResponsefrom django.contrib.auth import authenticatefrom django.contrib.auth.models import Userfrom django.contrib.auth import authenticate, login# Create your views here.def signup(request):if request.method == "POST":if request.POST['password1'] == request.POST['password2']:try:User.objects.get(username=request.POST['username'])return render(request,'accounts/signup.html',{'error':"Username already exist"})except User.DoesNotExist:user=User.objects.create_user(request.POST['username'],request.POST['password1'])login(request,user)return render(request,'accounts/signup.html',{'error':"user account created Successfully "})else:return render(request,'accounts/signup.html',{'error':"password didnt match"})else:return render(request,'accounts/signup.html')def loginview(request):if request.method=="POST":username=request.POST['username']password=request.POST['password']user=authenticate(username=username,password=password)if user is not None:login(request,user)return render(request,'accounts/login.html',{"error":"Login successful!!"})else:return render(request,'accounts/login.html',{"error":"username and password didnt match"})else:return render(request,'accounts/login.html')Note : when i enter login credentials , i unable to get message " Login successful" . please solve me on thisurls.py :=====from django.contrib import adminfrom django.urls import pathimport accounts.viewsurlpatterns = [path('admin/', admin.site.urls),path('signup/', accounts.views.signup,name='signup'),path('login/', accounts.views.loginview,name='login'),]login.html:=======<h1>Login</h1>{% if error %}{{ error }}<br><br>{% endif %}<form method = "POST" action="{% url 'login' %}">{% csrf_token %}Username:<br><input type="text" name="username" placeholder = "username"><br>Password:<br><input type="password" name="password" placeholder="password"><br><br><input type="submit" value ="Login"></form>
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d84911f-2d68-49b6-9fce-10708f993442n%40googlegroups.com.
No comments:
Post a Comment