Ошибка: argument of type 'function' is not iterable при добавление системы для регистрации пользователя
urls.py:
from django.contrib import admin
from django.urls import path
from myapp1.views import index, about, work, regist
from myapp1.views import register
urlpatterns = [
path('admin/', admin.site.urls),
path('', index),
path('prices/', about),
path('drinks/', work),
path('regist/', register, name=regist),
]
models.py:
from django.db import models
# Create your models here.
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
# Дополнительные поля, если нужно
pass
views.py:
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'index.html')
def about(request):
return render(request, 'about.html')
def work(request):
return render(request, 'work.html')
def regist(request):
return render(request, 'regist.html')
from django.shortcuts import render, redirect
from myapp1.forms import CustomUserCreationForm
def register(request):
if request.method == 'POST':
form = CustomUserCreationForm(request.POST)
if form.is_valid():
form.save()
return redirect('login')
else:
form = CustomUserCreationForm()
return render(request, 'registration_form.html', {'form': form})
forms.py:
from django import forms
from django.contrib.auth.forms import UserCreationForm
from myapp1.models import CustomUser
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = CustomUser
fields = ('username', 'email')
regist.html:
<!-- registration_form.html -->
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Зарегистрироваться</button>
</form>
Полная ошибка:
Watching for file changes with StatReloader Performing system checks...
Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner self.run() File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run self._target(*self._args, **self._kwargs) File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\runserver.py", line 133, in inner_run self.check(display_num_errors=True) File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 485, in check all_issues = checks.run_checks( File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases) File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
return check_resolver(resolver) File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
return check_method() File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 517, in check messages.extend(check_resolver(pattern)) File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
return check_method() File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 408, in check warnings = self._check_pattern_name() File "C:\Users\Ризамат\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 417, in _check_pattern_name
if self.pattern.name is not None and ":" in self.pattern.name: TypeError: argument of type 'function' is not iterable