1. <legend id='NG673'><style id='NG673'><dir id='NG673'><q id='NG673'></q></dir></style></legend>
  2. <small id='NG673'></small><noframes id='NG673'>

      • <bdo id='NG673'></bdo><ul id='NG673'></ul>

    1. <tfoot id='NG673'></tfoot>
    2. <i id='NG673'><tr id='NG673'><dt id='NG673'><q id='NG673'><span id='NG673'><b id='NG673'><form id='NG673'><ins id='NG673'></ins><ul id='NG673'></ul><sub id='NG673'></sub></form><legend id='NG673'></legend><bdo id='NG673'><pre id='NG673'><center id='NG673'></center></pre></bdo></b><th id='NG673'></th></span></q></dt></tr></i><div id='NG673'><tfoot id='NG673'></tfoot><dl id='NG673'><fieldset id='NG673'></fieldset></dl></div>

      如何在我自己的模板中使用内置的密码重置/更改视图

      时间:2023-09-28

            • <bdo id='gg2Gb'></bdo><ul id='gg2Gb'></ul>
              <tfoot id='gg2Gb'></tfoot>

              • <small id='gg2Gb'></small><noframes id='gg2Gb'>

              • <legend id='gg2Gb'><style id='gg2Gb'><dir id='gg2Gb'><q id='gg2Gb'></q></dir></style></legend>
                  <tbody id='gg2Gb'></tbody>
                <i id='gg2Gb'><tr id='gg2Gb'><dt id='gg2Gb'><q id='gg2Gb'><span id='gg2Gb'><b id='gg2Gb'><form id='gg2Gb'><ins id='gg2Gb'></ins><ul id='gg2Gb'></ul><sub id='gg2Gb'></sub></form><legend id='gg2Gb'></legend><bdo id='gg2Gb'><pre id='gg2Gb'><center id='gg2Gb'></center></pre></bdo></b><th id='gg2Gb'></th></span></q></dt></tr></i><div id='gg2Gb'><tfoot id='gg2Gb'></tfoot><dl id='gg2Gb'><fieldset id='gg2Gb'></fieldset></dl></div>
                本文介绍了如何在我自己的模板中使用内置的密码重置/更改视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                例如,我可以使用我的模板文件名将 url '^/accounts/password/reset/$' 指向 django.contrib.auth.views.password_reset上下文,但我认为需要发送更多上下文详细信息.

                For example I can point the url '^/accounts/password/reset/$' to django.contrib.auth.views.password_reset with my template filename in the context but I think need to send more context details.

                我需要确切知道要为每个密码重置和更改视图添加什么上下文.

                I need to know exactly what context to add for each of the password reset and change views.

                推荐答案

                如果你看一下 django.contrib.auth.views.password_reset 你会看到它使用 RequestContext.结果是,您可以使用上下文处理器来修改上下文,这可能允许您注入您需要的信息.

                If you take a look at the sources for django.contrib.auth.views.password_reset you'll see that it uses RequestContext. The upshot is, you can use Context Processors to modify the context which may allow you to inject the information that you need.

                b-list 有很好的 上下文处理器简介.

                The b-list has a good introduction to context processors.

                编辑(我似乎对实际问题感到困惑):

                Edit (I seem to have been confused about what the actual question was):

                您会注意到 password_reset 采用名为 template_name 的命名参数:

                You'll notice that password_reset takes a named parameter called 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 了解更多信息.

                Check password_reset for more information.

                ... 因此,使用 urls.py 如下:

                ... thus, with a urls.py like:

                from django.conf.urls.defaults import *
                from django.contrib.auth.views import password_reset
                
                urlpatterns = patterns('',
                     (r'^/accounts/password/reset/$', password_reset, {'template_name': 'my_templates/password_reset.html'}),
                     ...
                )
                

                django.contrib.auth.views.password_reset 将调用匹配 '/accounts/password/reset' 与关键字参数 template_name = ' 的 URLmy_templates/password_reset.html'.

                django.contrib.auth.views.password_reset will be called for URLs matching '/accounts/password/reset' with the keyword argument template_name = 'my_templates/password_reset.html'.

                否则,您不需要提供任何上下文,因为 password_reset 视图会自行处理.如果您想查看可用的上下文,可以触发 TemplateSyntax 错误并查看堆栈跟踪,找到带有名为 context 的局部变量的框架.如果你想修改上下文,那么我上面所说的上下文处理器可能是要走的路.

                Otherwise, you don't need to provide any context as the password_reset view takes care of itself. If you want to see what context you have available, you can trigger a TemplateSyntax error and look through the stack trace find the frame with a local variable named context. If you want to modify the context then what I said above about context processors is probably the way to go.

                总而言之:您需要做什么才能使用自己的模板?在调用视图时为视图提供 template_name 关键字参数.您可以通过将字典作为 URL 模式元组的第三个成员来为视图提供关键字参数.

                In summary: what do you need to do to use your own template? Provide a template_name keyword argument to the view when it is called. You can supply keyword arguments to views by including a dictionary as the third member of a URL pattern tuple.

                这篇关于如何在我自己的模板中使用内置的密码重置/更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:验证密码 - Python 下一篇:如何在 Python 中测试正则表达式密码?

                相关文章

                  <legend id='RAMWV'><style id='RAMWV'><dir id='RAMWV'><q id='RAMWV'></q></dir></style></legend>
                    <bdo id='RAMWV'></bdo><ul id='RAMWV'></ul>

                    <tfoot id='RAMWV'></tfoot>
                  1. <i id='RAMWV'><tr id='RAMWV'><dt id='RAMWV'><q id='RAMWV'><span id='RAMWV'><b id='RAMWV'><form id='RAMWV'><ins id='RAMWV'></ins><ul id='RAMWV'></ul><sub id='RAMWV'></sub></form><legend id='RAMWV'></legend><bdo id='RAMWV'><pre id='RAMWV'><center id='RAMWV'></center></pre></bdo></b><th id='RAMWV'></th></span></q></dt></tr></i><div id='RAMWV'><tfoot id='RAMWV'></tfoot><dl id='RAMWV'><fieldset id='RAMWV'></fieldset></dl></div>

                    <small id='RAMWV'></small><noframes id='RAMWV'>