Эта ошибка возникает при нажатии на кнопку отправить после заполнения формы. Я стараюсь следовать этому руководству, но использую bootstrap шаблоны для страницы регистрации https://dev.to/coderasha/create-advanced-user-sign-up-view-in-django-step-by-step-k9m
views.py
from django.shortcuts import render
from django.contrib.auth import login, authenticate
from .forms import SignUpForm
from django.shortcuts import render, redirect
def home(request):
return render(request, 'home.html')
def signup(request):
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=password)
login(request, user)
return redirect('home')
else:
form = SignUpForm()
return render(request, 'signup.html', {'form': form})
app1 / urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name="home"),
path('signup/', views.signup, name='signup'),
]
регистрация. html
<form role="form" action="signup" method="POST">
{% csrf_token %}
формы. html
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class SignUpForm(UserCreationForm):
username = forms.CharField(max_length=30)
email = forms.EmailField(max_length=200)
class Meta:
model = User
fields = ('username','first_name','last_name','email', 'password1', 'password2', )