Python SyntaxError:URLpattern中的语法无效

Python SyntaxError:URLpattern中的语法无效,python,django,syntax,Python,Django,Syntax,嗨,我收到一个语法错误 网址: 有什么问题 谢谢问题在于您将字典语法与参数语法混合使用: url( r'^reset-password/$', PasswordResetView.as_view( template_name='accounts/reset_password.html', 'post_reset_redirect': 'accounts:password_reset_done' ), name='reset_pass

嗨,我收到一个语法错误

网址:

有什么问题


谢谢

问题在于您将字典语法与参数语法混合使用:

url(
    r'^reset-password/$',
    PasswordResetView.as_view(
        template_name='accounts/reset_password.html',
        'post_reset_redirect': 'accounts:password_reset_done'
    ),
    name='reset_password'
)
post\u reset\u redirect
已作为参数删除,但
success\u url
执行相同的功能:它是成功处理post请求后执行重定向的url

错误的语法可能源于这样一个事实:当您使用基于函数的视图时,您通过接受字典的
kwargs
parameter传递参数


然而,基于类的视图通过
.as\u视图(..)
调用获取这些参数。此外,基于类的视图通常旨在概括该过程,其中的
success\u url
用于
FormView
s。

您在
的“重置后重定向”中使用了
冒号:'accounts:password\u reset\u done'
,而不是
post\u reset\u redirect='accounts:password\u reset\u done'
。谢谢,我现在收到了这个错误:TypeError:PasswordResetView()收到了一个无效的关键字“post\u reset\u redirect”。as_view只接受已经是类属性的参数。当我这样做时,我在urlpattern末尾得到urlpattern右括号的语法错误]…我尝试过了),但是我得到的是'NameError:name'reverse_lazy'不是defined@JosephS:没有,YY您需要导入它:
从django.url导入reverse_lazy
。括号是-afaik-正确的(请注意,我们两个都用粗体显示,一个在第二行,另一个在下一行)。
url(
    r'^reset-password/$',
    PasswordResetView.as_view(
        template_name='accounts/reset_password.html',
        'post_reset_redirect': 'accounts:password_reset_done'
    ),
    name='reset_password'
)
from django.urls import reverse_lazy

url(
    r'^reset-password/$',
    PasswordResetView.as_view(
        template_name='accounts/reset_password.html',
        success_url=reverse_lazy('accounts:password_reset_done')
    ),
    name='reset_password'
)