У страницы signup.html есть URL-адрес, как показано
urls.py
urlpatterns = [
...
path('signup', views.Sign_up,name="signup"),
...
]
signup.html
<form class="signup-form initial-signup-form gtm_signup_register_form" action="." accept-charset="UTF-8" method="POST">
...
</form>
Но когда форма отправляется вместо доступа к представлению Registration (), она указывает на Login_view ().Я получил вывод как «неверные данные для входа!».Но ожидаемый результат - home.html.
views.py
def Sign_up(request):
Fname = request.POST.get("first_name")
Lname = request.POST.get("last_name")
Mno = request.POST.get("Mobile")
email = request.POST.get("email")
Pass = request.POST.get("pass")
Role = request.POST.get("role")
Loc = request.POST.get("self_loc")
if request.method == "POST":
userM = UserManager()
if Role=="Consumer":
userV= userM.create_user(Mno,Role,Pass)
else:
userV= userM.create_staffuser(Mno,Role,Pass)
userV.first_name=Fname
userV.last_name=Lname
userV.email=email
userV.location=Loc
return render(request, "home.html", {})
else:
return render(request, "registration/signup.html", {})
def Login_view(request):
print(request.method)
if request.method == "POST":
Uname = request.POST.get("Mobile")
PassW = request.POST.get("password")
print(Uname, PassW)
user = authenticate(mobile_no = Uname, password=PassW)
if user:
if user.is_active:
login(request,user)
if user.is_staff:
return HttpResponseRedirect(reverse('index'))
else:
return HttpResponseRedirect(reverse('home'))
else:
return HttpResponse("Account Not Active")
else:
print("Someone tried to login and failed")
print("Mobile_no: {} and password {}".format(Uname,PassW))
return HttpResponse("invalid login details supplied!")
else:
return render(request,"registration/login.html", {})