Django:密码重设电子邮件主题行包含“ example.com [英] Django: Password reset email subject line contains 'example.com
问题描述
我将通用视图django.contrib.auth.views.password_reset用于密码重置表单。原则上,所有工作都可以,但发送的电子邮件的主题行包含 example.com,例如:在example.com上重置密码。
I'm using the generic view django.contrib.auth.views.password_reset for the password reset form. In principle, it all works, except that the subject line of the email that's sent out contains 'example.com', as in: "Password reset on example.com".
所以我环顾四周,但是对于我一生来说,我无法找到如何更改它以包含我的实际域名的方法。
So I have looked around, but for the life of me I cannot find out how I can change this to contain my actual domain name.
有什么想法吗?
推荐答案
PasswordResetForm
根据您的 contrib.sites发送电子邮件
。它获取要使用的域名,并将其传递给 registration / password_reset_email.html
The PasswordResetForm
sends the email based on your contrib.sites
. It gets the domain name to use and passes it to the html template at registration/password_reset_email.html
django / trunk / django / contrib / auth / forms.py:
...
4 from django.contrib.sites.models import get_current_site
...
123 def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
124 use_https=False, token_generator=default_token_generator, from_email=None, request=None):
125 """
126 Generates a one-use only link for resetting password and sends to the user
127 """
128 from django.core.mail import send_mail
129 for user in self.users_cache:
130 if not domain_override:
131 current_site = get_current_site(request)
132 site_name = current_site.name
133 domain = current_site.domain
134 else:
135 site_name = domain = domain_override
136 t = loader.get_template(email_template_name)
137 c = {
138 'email': user.email,
139 'domain': domain,
140 'site_name': site_name,
141 'uid': int_to_base36(user.id),
142 'user': user,
143 'token': token_generator.make_token(user),
144 'protocol': use_https and 'https' or 'http',
145 }
146 send_mail(_("Password reset on %s") % site_name,
147 t.render(Context(c)), from_email, [user.email])
使用管理员或django shell更改网站
use admin or django shell to change the site
了解有关网站框架 此处
。
Django如何使用站点框架
How Django uses the sites framework
尽管不需要
使用站点框架,但强烈建议您使用
,因为Django
在几个地方的优势。即使
(如果您的Django安装是
仅为单个站点供电),您
也应该花两秒钟的时间来创建
具有您的域和
名称的站点对象,并且指向
SITE_ID设置中的ID。
Although it's not required that you use the sites framework, it's strongly encouraged, because Django takes advantage of it in a few places. Even if your Django installation is powering only a single site, you should take the two seconds to create the site object with your domain and name, and point to its ID in your SITE_ID setting.
在shell中,您可以这样做:
in shell you can do this by doing:
>>> from django.contrib.sites.models import Site
>>> my_site = Site(domain='some_domain.com', name='Some Domain')
>>> my_site.save()
>>> print my_site.id
2
>>>
在您的settings.py中:
in your settings.py:
SITE_ID = 2
或
>>> my_site = Site.objects.get(pk=1)
>>> my_site.domain = 'somedomain.com'
>>> my_site.name = 'Some Domain'
>>> my_site.save()
在您的settings.py中:
in your settings.py:
SITE_ID = 1
这篇关于Django:密码重设电子邮件主题行包含“ example.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!