“PasswordResetView”需要1个位置参数,但提供了2个。

huangapple go评论150阅读模式
英文:

PasswordResetView takes 1 positional argument but 2 were given

问题

Here's the translated code portion:

  1. def password_recover(request):
  2. print("password_recover")
  3. return password_reset(request, subject_template_name='registration/password_reset_subject.txt')
  1. def password_recover(request):
  2. print("password_recover")
  3. 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"

英文:
  1. def password_recover(request):
  2. print("password_recover")
  3. 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

  1. def password_recover(request):
  2. print("password_recover")
  3. 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

以下是翻译好的部分:

不能像这样使用它,正确的示例应该是:

  1. from django.contrib.auth.forms import PasswordResetForm
  2. from django.contrib.auth import views as auth_views
  3. class PasswordResetView(auth_views.PasswordResetView):
  4. subject_template_name = 'registration/password_reset_subject.txt'

urls.py 中:

  1. urlpatterns = [
  2. path('', views.PasswordResetView.as_view())
  3. ]

请注意,PasswordResetView 是一个基于类的视图,您需要调用 .as_view() 方法。

英文:

You can not use it like so, the correct example would be:

  1. from django.contrib.auth.forms import PasswordResetForm
  2. from django.contrib.auth import views as auth_views
  3. class PasswordResetView(auth_views.PasswordResetView):
  4. subject_template_name = 'registration/password_reset_subject.txt'

and in urls.py

  1. urlpatterns = [
  2. path('', views.PasswordResetView.as_view())
  3. ]

Take a note that PasswordResetView is a class-based view and you need to call .as_view() method.

huangapple
  • 本文由 发表于 2020年1月7日 01:06:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616189.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定