如果您查看django.contrib.auth.views.password_reset的源代码,您会发现它使用
RequestContext。结果是,您可以使用上下文处理器来修改上下文,这可以允许您注入所需的信息。
b-list对上下文处理器有很好的介绍。
编辑(我似乎对实际问题感到困惑):
您会注意到,
password_reset它带有一个名为的命名参数
template_name:
def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', email_template_name='registration/password_reset_email.html', password_reset_form=PasswordResetForm, token_generator=default_token_generator, post_reset_redirect=None):
检查password_reset以获取更多信息。
因此,使用类似urls.py的代码:
from django.conf.urls.defaults import *from django.contrib.auth.views import password_reseturlpatterns = patterns('', (r'^/accounts/password/reset/$', password_reset, {'template_name': 'my_templates/password_reset.html'}), ...)django.contrib.auth.views.password_reset``'/accounts/password/reset'与关键字参数匹配的URL将被调用
template_name= 'my_templates/password_reset.html'。
否则,您无需提供任何上下文,因为
password_reset视图会自行处理。如果您想查看可用的上下文,则可以触发
TemplateSyntax错误,并在堆栈跟踪中查找带有名为的局部变量的框架
context。如果要修改上下文,那么我上面所说的关于上下文处理器的方法可能就是解决方法。
总结:使用自己的模板需要做什么?
template_name在调用视图时,为视图提供关键字参数。您可以通过将字典作为URL模式元组的第三个成员来为视图提供关键字参数。



