Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am i getting __init__() takes 1 positional argument but 2 were given?

Tags:

python

django

I am working on a project and I am getting this following error:

traceback:

TypeError at /account/reset-password
__init__() takes 1 positional argument but 2 were given

imports:

from django.conf.urls import url
from . import views
from django.contrib.auth import views as auth_views
from django.contrib.auth.views import PasswordResetView, PasswordResetDoneView

url:

url(r'^reset-password$', PasswordResetView, name='reset_password'),

I am new to django, so welcomed help . ty

like image 493
JosephS Avatar asked Jan 02 '23 20:01

JosephS


1 Answers

The PasswordResetView [Django-doc] is a class-based view, you should specify the URL as:

url(r'^reset-password$', PasswordResetView.as_view(), name='reset_password'),

You do not want to create a new PasswordResetView each time you pass to the view, you want to create a HTTP response. The reason why you get the error is because now you will create a PasswordResetView (so you will call the __init__(..) method of the PasswordResetView class. There is a mismatch between the parameters used by the view, and the constructor of the object, hence the error. Even if there was no mismatch, there would - luckily enough - still be an error, since the result would be a PasswordResetView object, which is not a subclass of a HttpResponse.

like image 118
Willem Van Onsem Avatar answered Jan 19 '23 00:01

Willem Van Onsem