Reputation: 191
hi am getting a syntax error
url:
url(r'^reset-password/$',
PasswordResetView.as_view(template_name='accounts/reset_password.html', 'post_reset_redirect': 'accounts:password_reset_done'), name='reset_password'),
What is the problem?
thanks
Upvotes: 1
Views: 394
Reputation: 477160
The problem is that you mix dictionary syntax with parameter syntax:
url(
r'^reset-password/$',
PasswordResetView.as_view(
template_name='accounts/reset_password.html',
'post_reset_redirect': 'accounts:password_reset_done'
),
name='reset_password'
)
This syntax with a colon, is used for dictionaries. For parameters, it is identifier=expression
, so:
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'
)
The post_reset_redirect
has been removed as parameter, but the success_url
performs the same functionality: it is the URL to which a redirect is done, after the POST request has been handled successfully.
The wrong syntax probably originates from the fact that when you used a function-based view, you passed parameters through the kwargs
paramter, which accepted a dictionary.
The class-based view however, obtains these parameter through the .as_view(..)
call. Furthermore class-based views typically aim to generalize the process, and there the success_url
, is used for FormView
s.
Upvotes: 3