[Python] How to fix "SignUpView is missing a QuerySet"

Discussão em 'Python' iniciado por Stack, Março 30, 2025.

  1. Stack

    Stack Membro Participativo

    In my django web app i am trying to build a Newspaper app, in my homepage when i click on SIGN UP Button i get an error "ImproperlyConfigured at /accounts/signup/", I didnt figure out where is the problem. forms.py:

    from django.contrib.auth.forms import UserCreationForm, UserChangeForm
    from .models import CustomUser

    class CustomUserCreationForm(UserCreationForm): #Creation of CustomUser

    class Meta:
    model = CustomUser
    fields = UserCreationForm.Meta.fields + ("age",)

    class CustomUserChangeForm(UserChangeForm): #Modifying existing users

    class Meta:
    model = CustomUser
    fields = UserChangeForm.Meta.fields


    and models.py:

    from django.contrib.auth.models import AbstractUser #username, pw1, pw2
    from django.db import models

    class CustomUser(AbstractUser):
    age = models.PositiveIntegerField(null=True, blank=True)



    urls.py:

    from django.urls import path
    from .views import SignUpView

    #Accounts/urls.py : Handles only registrations URLs!!
    urlpatterns = [
    path('signup/', SignUpView.as_view(), name='signup'),
    ]



    and views.py:

    from django.urls import reverse_lazy
    from django.views.generic import CreateView
    from .forms import CustomUserCreationForm

    class SignUpView(CreateView):
    from_class = CustomUserCreationForm
    success_url = reverse_lazy('login')
    template_name = 'registration/signup.html'


    signup.html:

    {% extends 'base.html' %}

    {% block title %}Sign Up{% endblock title %}

    {% block content %}
    <h2>Sign Up</h2>
    <form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Sign Up</button>
    </form>
    {% endblock content %}


    I tried to change fields in forms.py with:

    fields = (
    "username",
    "email",
    "age",)


    but nothing to be mention

    Continue reading...

Compartilhe esta Página