Home > front end >  TypeError at /accounts/signup/ View.__init__() takes 1 positional argument but 2 were given
TypeError at /accounts/signup/ View.__init__() takes 1 positional argument but 2 were given

Time:12-06

I am using Django allauth to authenticate users to signup and login. But this error TypeError at /accounts/signup/ View.__init__() takes 1 positional argument but 2 were given comes up as I try to access django allauth signup and login templates.

urls.py:

from django.urls import path
from allauth.account import views as allauthViews
from . import views



urlpatterns = [
    path("", views.index, name="index"),
    path("<int:myid>/", views.quiz, name="quiz"), 
    path('<int:myid>/data/', views.quiz_data_view, name='quiz-data'),
    path('<int:myid>/save/', views.save_quiz_view, name='quiz-save'),
    
    path("accounts/signup/", allauthViews.SignupView, name="account_signup"),
    path("accounts/login/", allauthViews.LoginView, name="account_login"),
    path("accounts/logout/", allauthViews.LogoutView, name="account_logout"),
    
    path('add_quiz/', views.add_quiz, name='add_quiz'),    
    path('add_question/', views.add_question, name='add_question'),  
    path('add_options/<int:myid>/', views.add_options, name='add_options'), 
    path('results/', views.results, name='results'),    
    path('delete_question/<int:myid>/', views.delete_question, name='delete_question'),  
    path('delete_result/<int:myid>/', views.delete_result, name='delete_result'),    
]

SignUpView

class SignupView(
    RedirectAuthenticatedUserMixin,
    CloseableSignupMixin,
    AjaxCapableProcessFormViewMixin,
    FormView,
):
    template_name = "account/signup."   app_settings.TEMPLATE_EXTENSION
    form_class = SignupForm
    redirect_field_name = "next"
    success_url = None

    @sensitive_post_parameters_m
    def dispatch(self, request, *args, **kwargs):
        return super(SignupView, self).dispatch(request, *args, **kwargs)

    def get_form_class(self):
        return get_form_class(app_settings.FORMS, "signup", self.form_class)

    def get_success_url(self):
        # Explicitly passed ?next= URL takes precedence
        ret = (
            get_next_redirect_url(self.request, self.redirect_field_name)
            or self.success_url
        )
        return ret

    def form_valid(self, form):
        # By assigning the User to a property on the view, we allow subclasses
        # of SignupView to access the newly created User instance
        self.user = form.save(self.request)
        try:
            return complete_signup(
                self.request,
                self.user,
                app_settings.EMAIL_VERIFICATION,
                self.get_success_url(),
            )
        except ImmediateHttpResponse as e:
            return e.response

    def get_context_data(self, **kwargs):
        ret = super(SignupView, self).get_context_data(**kwargs)
        form = ret["form"]
        email = self.request.session.get("account_verified_email")
        if email:
            email_keys = ["email"]
            if app_settings.SIGNUP_EMAIL_ENTER_TWICE:
                email_keys.append("email2")
            for email_key in email_keys:
                form.fields[email_key].initial = email
        login_url = passthrough_next_redirect_url(
            self.request, reverse("account_login"), self.redirect_field_name
        )
        redirect_field_name = self.redirect_field_name
        site = get_current_site(self.request)
        redirect_field_value = get_request_param(self.request, redirect_field_name)
        ret.update(
            {
                "login_url": login_url,
                "redirect_field_name": redirect_field_name,
                "redirect_field_value": redirect_field_value,
                "site": site,
            }
        )
        return ret


callback    
<class 'allauth.account.views.SignupView'>
callback_args   
()
callback_kwargs 
{}
middleware_method   
<bound method CsrfViewMiddleware.process_view of <django.middleware.csrf.CsrfViewMiddleware object at 0x0000017B8F25B070>>
request 
<WSGIRequest: GET '/accounts/signup/'>
response    
None
self    
<django.core.handlers.wsgi.WSGIHandler object at 0x0000017B8DF32290>
wrapped_callback    
<class 'allauth.account.views.SignupView'>

CodePudding user response:

You need to use as_view() in your urls

…
urlpatterns = [
    …
    path("accounts/signup/", allauthViews.SignupView.as_view(), name="account_signup"),
    path("accounts/login/", allauthViews.LoginView.as_view(), name="account_login"),
    path("accounts/logout/", allauthViews.LogoutView.as_view(), name="account_logout"),
    … 
]

  • Related