views.py:
@login_required
@csrf_protect
def password_change(request,
template_name='password_change_form.html',
password_change_form=PasswordChangeForm,):
if request.method == 'POST':
form = password_change_form(user=request.user, data=request.POST)
if form.is_valid():
form.save()
update_session_auth_hash(request, form.user)
return HttpResponseRedirect(reverse('student:password_change_done'))
else:
form = password_change_form(user=request.user)
context = {
'form': PasswordChangeForm,
'title': _('Password change'),
'current_app': 'student',
}
return TemplateResponse(request, template_name, context)
@login_required
def password_change_done(request,
template_name='password_change_done.html',):
context = {
'title': _('Password change successful'),
}
return TemplateResponse(request, template_name, context)
my urls.py:
from django.conf.urls import url, patterns
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^register/$', views.register, name='register'),
url(r'^login/$', views.user_login, name='login'),
url(r'^logout/$', views.user_logout, name='logout'),
url(r'^password_change/$', auth_views.password_change, {'template_name': 'password_change_form.html'}, name="password_change"),
url(r'^password_change/done/$', auth_views.password_change_done, {'template_name': 'password_change_done.html'}, name="password_change_done"),
url(r'^restricted/', views.restricted, name='restricted'),
url(r'^mains/', views.mains, name = 'mains'),
]
我的'password_change'
表单工作正常但是当我点击提交按钮时,它会将我重定向到以下网址: - 'http://127.0.0.1:8000/stu/password_change/None'
根据我的观点,尽管'http://127.0.0.1:8000/stu/password_change/done'
符合预期和网址。
我在某个地方做错了吗?
请帮助我进入它?
谢谢!提前
答案 0 :(得分:0)
您在login_required decorator
中使用password_change_done
这意味着必须对您的用户进行身份验证才能访问该视图。
更改密码后,您将不再进行身份验证。在password_change
视图中,您必须在更改密码后进行身份验证并登录您的用户。