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".
我使用的是通用视图django.致歉。密码重置表单的password_reset。原则上,这一切都是可行的,除了发送的邮件的主题行包含“example.com”,如“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.
所以我环顾四周,但对于我的生活,我无法找到如何改变它来包含我的实际域名。
Any ideas?
什么好主意吗?
2 个解决方案
#1
17
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
PasswordResetForm根据您的设计发送电子邮件。它获取要使用的域名,并将其传递到注册/password_reset_email.html的html模板
django/trunk/django/contrib/auth/forms.py:
django /箱子/ django / contrib /认证/ 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])
use admin or django shell to change the site
使用admin或django shell更改站点
read more about the sites framework here
.
在这里阅读更多关于站点框架的信息。
How Django uses the sites framework
Django如何使用站点框架
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.
虽然不需要使用sites框架,但是强烈鼓励使用它,因为Django在一些地方利用了它。即使Django安装只支持一个站点,您也应该花两秒钟时间使用您的域和名称创建站点对象,并在您的SITE_ID设置中指向它的ID。
in shell you can do this by doing:
在shell中,您可以这样做:
>>> 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
>>>
in your settings.py:
在你settings.py:
SITE_ID = 2
or
或
>>> my_site = Site.objects.get(pk=1)
>>> my_site.domain = 'somedomain.com'
>>> my_site.name = 'Some Domain'
>>> my_site.save()
in your settings.py:
在你settings.py:
SITE_ID = 1
#2
1
Assuming you have the admin site up go to the "sites" group and change the first one there to your domain?
假设你有管理网站到“网站”组并把第一个改变到你的域名?
Either that or there is something in settings.py.
http://docs.djangoproject.com/en/dev/topics/settings/#the-basics
要么是这个,要么是settings。py。http://docs.djangoproject.com/en/dev/topics/settings/基础
I'll just check and find out for you
我帮你查一下
EDIT:
编辑:
I am fairly certain thats what I did to make it work for me.
我相当肯定这就是我为自己所做的。
#1
17
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
PasswordResetForm根据您的设计发送电子邮件。它获取要使用的域名,并将其传递到注册/password_reset_email.html的html模板
django/trunk/django/contrib/auth/forms.py:
django /箱子/ django / contrib /认证/ 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])
use admin or django shell to change the site
使用admin或django shell更改站点
read more about the sites framework here
.
在这里阅读更多关于站点框架的信息。
How Django uses the sites framework
Django如何使用站点框架
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.
虽然不需要使用sites框架,但是强烈鼓励使用它,因为Django在一些地方利用了它。即使Django安装只支持一个站点,您也应该花两秒钟时间使用您的域和名称创建站点对象,并在您的SITE_ID设置中指向它的ID。
in shell you can do this by doing:
在shell中,您可以这样做:
>>> 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
>>>
in your settings.py:
在你settings.py:
SITE_ID = 2
or
或
>>> my_site = Site.objects.get(pk=1)
>>> my_site.domain = 'somedomain.com'
>>> my_site.name = 'Some Domain'
>>> my_site.save()
in your settings.py:
在你settings.py:
SITE_ID = 1
#2
1
Assuming you have the admin site up go to the "sites" group and change the first one there to your domain?
假设你有管理网站到“网站”组并把第一个改变到你的域名?
Either that or there is something in settings.py.
http://docs.djangoproject.com/en/dev/topics/settings/#the-basics
要么是这个,要么是settings。py。http://docs.djangoproject.com/en/dev/topics/settings/基础
I'll just check and find out for you
我帮你查一下
EDIT:
编辑:
I am fairly certain thats what I did to make it work for me.
我相当肯定这就是我为自己所做的。