密码重置未重定向到Django中的模板

时间:2018-08-09 01:59:38

标签: django django-registration django-rest-auth

我正在尝试覆盖默认电子邮件,以使用html模板在Django rest-auth中重置密码。

我正在尝试使用:

from django.conf.urls import url
from django.contrib.auth import views as auth_views

urlpatterns = [
    url(r'^password/reset/', auth_views.password_reset,
    {
        'html_email_template_name':'registration/password_reset_email_html.html',
    }, 
    name="password_reset"),
    url('^', include('django.contrib.auth.urls')),
]

电子邮件已成功发送,但是具有默认模板。 我可以通过添加自定义模板文件registration/password_reset_email.html来覆盖此设置,但随后该电子邮件仅以纯文本格式发送。

我在这里做什么错了?

2 个答案:

答案 0 :(得分:0)

我们之前也遇到过这种情况,我们使用了django.core.mail中的EmailMultiAlternatives发送html电子邮件。

这是示例代码:

def custom_send_mail(to_email,subject,html_email_template_name=None,context=None,from_email = None):
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
email_message = EmailMultiAlternatives(subject, subject, from_email, [to_email])
#html_email_template_name = "registration/password_reset_confirm_html_email.html"
if html_email_template_name is not None:
    html_email = loader.render_to_string(html_email_template_name,context)
    email_message.attach_alternative(html_email, 'text/html')

email_message.send()

答案 1 :(得分:0)

select * 
from info 
where begindate > '06/30/2018'

select * 
from info 
where convert(varchar, begindate, 101) > '06/30/2018'

按照上面的urlpattern进行操作,可能会有所帮助。 另请参阅:https://simpleisbetterthancomplex.com/tutorial/2016/09/19/how-to-create-password-reset-view.html