нет перенаправления из auth_view.LoginView.as_view (authentication_form = LoginForm) - PullRequest
0 голосов
/ 01 мая 2020

Я использую auth_view.LoginView.as_view () urls.py в качестве имени входа по умолчанию в django. Чтобы добавить больше полей, я использовал пользовательскую форму с AuthenticationForm в form.py, но после использования пользовательской формы я не могу перенаправить со страницы входа в систему, так как я нажимаю кнопку отправки

, вот мой form.py '' *

from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import AuthenticationForm

class LoginForm(AuthenticationForm):
    user_type_choice = (('visitor', 'Visitor'),('guest', 'Guest'),('contractor', 
    'Contractor'))
    username = forms.CharField()
    password = forms.CharField(widget=forms.PasswordInput)
    user_type = forms.MultipleChoiceField(choices=user_type_choice, 
    widget=forms.NullBooleanSelect, required=True)

вот мой urls.py

from django.urls import path
from django.contrib.auth import views as auth_view
from account.form import LoginForm
from . import views
urlpatterns =[
    path('login/', auth_view.LoginView.as_view(authentication_form=LoginForm), 
name='login'),
    path('logout/', auth_view.LogoutView.as_view(), name='logout'),
    path('', views.dashboard, name='dashboard')
]

вот мой views.py

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
# Create your views here.

@login_required
def dashboard(request):
    render(request, 'account/dashboard', {'section': dashboard})

извините за плохой английский sh. я новичок ie, прошу прощения за мои ошибки

вот логин. html

{%load static%}
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet"  type='text/css' href="{%static 'css/loginstyle.css'%}">
        <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@800&display=swap" rel="stylesheet">
        <title></title>
    </head>
    <body>
        <div class='header'>
            <img src="{%static 'img/healthlogo.png'%}" height="80" weidth="80">
        <h1>AGED CARE PORTAL
        </h1>
        </div>
        <form method="POST" class="form">
             {%csrf_token%}
             <br>
             <br>
             <input align='center' class="credentials" placeholder="ID"{{form.username}}
             </div>
             <br>
              <div>
             <input class="credentials" placeholder="Password" {{form.password}}
            </div>
             <div align='center' >
             <select class='selector'{{form.user_type}}</select>
             </div>
             <p align='center'><input  class='logtton' type='submit' value='Log-In'></p>
             <input type="hidden" name="next" value="{{next}}">
        </form>
    </body>
</html>
...