我想有自己的自定义change_password
页面,我已经使用管理员登录从Django(使用from django.contrib.auth.decorators import login_required
)。
使管理员登录工作,但想要更改的change_password
页面。
我该怎么做?
我不确定如何链接到管理员登录,或者因为我想自定义我的change_password,我也必须自定义我的管理员登录?
需要一些指导。谢谢..。
发布于 2012-06-29 12:41:50
您可以导入表单
from django.contrib.auth.views import password_change
如果你看一下Django的password_change视图。你会注意到,它需要一个视图参数,你可以提供这些参数来定制视图以满足你自己的需求,从而使你的webapp更加枯燥。
def password_change(request,
template_name='registration/password_change_form.html',
post_change_redirect=None,
password_change_form=PasswordChangeForm,
current_app=None, extra_context=None):
if post_change_redirect is None:
post_change_redirect = reverse('django.contrib.auth.views.password_change_done')
if request.method == "POST":
form = password_change_form(user=request.user, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(post_change_redirect)
else:
form = password_change_form(user=request.user)
context = {
'form': form,
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context,
current_app=current_app)
最值得注意的是,template_name
和extra_context
使您的视图看起来像这样
from django.contrib.auth.views import password_change
def my_password_change(request)
return password_change(template_name='my_template.html', extra_context={'my_var1': my_var1})
发布于 2012-06-29 09:30:08
Django的模板查找器允许您覆盖任何模板,只需在您的模板文件夹中添加您想要覆盖的管理模板,例如:
templates/
admin/
registration/
password_change_form.html
password_reset_complete.html
password_reset_confirm.html
password_reset_done.html
password_reset_email.html
password_reset_form.html
https://stackoverflow.com/questions/11257607
复制