Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 覆盖Django';s重置密码电子邮件模板_Python_Django_Email_Templates - Fatal编程技术网

Python 覆盖Django';s重置密码电子邮件模板

Python 覆盖Django';s重置密码电子邮件模板,python,django,email,templates,Python,Django,Email,Templates,在我的Django应用程序中,我想定制当用户请求重置密码时发送给他们的电子邮件。我将这些模板保存在我的项目的模板目录中 /templates/email/password\u reset/password\u reset.html用于html电子邮件 /templates/email/password\u reset/password\u reset.txt用于普通电子邮件 主题的/templates/email/password\u reset/password\u reset\u subj

在我的Django应用程序中,我想定制当用户请求重置密码时发送给他们的电子邮件。我将这些模板保存在我的项目的
模板
目录中

  • /templates/email/password\u reset/password\u reset.html
    用于html电子邮件
  • /templates/email/password\u reset/password\u reset.txt
    用于普通电子邮件
  • 主题的
    /templates/email/password\u reset/password\u reset\u subject.txt
在我的URL模式中,我有

urlpatterns = [

...

    url('^password_reset/$', auth_views.password_reset,
        {
            'template_name': 'accounts/reset_password.html',
            'email_template_name': 'email/password_reset/password_reset.txt',
            'html_email_template_name': 'email/password_reset/password_reset.html',
            'subject_template_name': 'email/password_reset/password_reset_subject.txt'
        },
        name='password_reset'),

...

]

但是,Django仍然使用默认密码重置模板发送电子邮件。我是不是漏掉了什么明显的东西?谢谢。

应该就这么简单()


事实证明,我在URL中意外地定义了两次
auth\u views.password\u reset
。删除副本修复了问题。

不确定,但。。如果你用等号传递参数?email_template_name'='email/password_reset/password_reset.txt'@avs谢谢你的评论。我认为url()函数将函数名和关键字参数列表作为字典,因此不必使用等号?您好@marksweb,谢谢您的回答。我认为没有必要使用kwargs名称,因为我将它作为第三个参数传递,所以Python知道我指的是什么,即使不必命名它。Django尊重“template_name”,其他什么都不尊重,所以它一定是通过了参数字典?@Kieran是的,所以说实话,我已经查过了&你是对的。如果您已经匹配了模板名称,就像您看起来已经匹配了一样,那么它应该可以工作。
url('^password_reset/$', auth_views.password_reset,
    {
        'template_name': 'accounts/reset_password.html',
        'email_template_name': 'email/password_reset/password_reset.txt',
        'html_email_template_name': 'email/password_reset/password_reset.html',
        'subject_template_name': 'email/password_reset/password_reset_subject.txt'
    },
    name='password_reset'),