0
0
0ralo2021-02-10 20:25:58
Django
0ralo, 2021-02-10 20:25:58

Why don't the passwords match?

Hello!
Now I'm learning janga and a strange problem has appeared. When you try to log in to your account or register, it doesn't work

When registering, an error occurs - password_mismatch Attention! even if the passwords were not entered, but inserted CTRL + V

When authorizing into an existing account, the error is invalid_logininactive

Files:

views.py
from django.contrib.auth import login
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm


def user_login(request):
  if request.method == "POST":
    form = AuthenticationForm()
    if form.is_valid():
      usr = form.get_user()
      login(request, usr)
      return HttpResponse("<h1>good</h1>")
    else:
      return HttpResponse(form.error_messages)
  else:
    form = AuthenticationForm()
    return render(request, "UserAuth/login.html", {"form": form})


def user_register(request):
  if request.method == "POST":
    form = UserCreationForm()
    if form.is_valid():
      usr = form.save()
      login(request, usr)
      return HttpResponse("<h1>good</h1>")
    else:
      return HttpResponse(form.error_messages)

  else:
    form = UserCreationForm()
    return render(request, "UserAuth/register.html", {"form": form})

urls.py
from django.urls import path
from .views import *

urlpatterns = [
  path("login/", user_login),
  path("register/", user_register),
]

templates/login.html
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Log in</title>
</head>
    <body>
    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <button type="submit">Go</button>
    </form>
    </body>
</html>

templates/register.html
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
    <body>
    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <button type="submit">Go</button>
    </form>
    </body>
</html>

Through the most difficult debugging, I found that is_valid () does not return True, although I did not write my own validation methods

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wispik, 2021-02-10
@0ralo

so in the form it seems like you need to pass data
form = AuthenticationForm(request.POST)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question