英文:
PasswordResetView takes 1 positional argument but 2 were given
问题
Here's the translated code portion:
def password_recover(request):
print("password_recover")
return password_reset(request, subject_template_name='registration/password_reset_subject.txt')
def password_recover(request):
print("password_recover")
return PasswordResetView(request, subject_template_name='registration/password_reset_subject.txt')
The error message remains the same in both versions:
"takes 1 positional argument but 2 were given"
英文:
def password_recover(request):
print("password_recover")
return password_reset(request, subject_template_name='registration/password_reset_subject.txt')
So I had that piece of code, that was working on django 1.8.While migrating to django 2.2, i changed that piece of code too the one below
def password_recover(request):
print("password_recover")
return PasswordResetView(request, subject_template_name='registration/password_reset_subject.txt')
I am getting error takes 1 positional argument but 2 were given
答案1
得分: 1
以下是翻译好的部分:
不能像这样使用它,正确的示例应该是:
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth import views as auth_views
class PasswordResetView(auth_views.PasswordResetView):
subject_template_name = 'registration/password_reset_subject.txt'
在 urls.py
中:
urlpatterns = [
path('', views.PasswordResetView.as_view())
]
请注意,PasswordResetView
是一个基于类的视图,您需要调用 .as_view()
方法。
英文:
You can not use it like so, the correct example would be:
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth import views as auth_views
class PasswordResetView(auth_views.PasswordResetView):
subject_template_name = 'registration/password_reset_subject.txt'
and in urls.py
urlpatterns = [
path('', views.PasswordResetView.as_view())
]
Take a note that PasswordResetView
is a class-based view and you need to call .as_view()
method.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论