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

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

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.

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:

确定