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.
Any ideas?
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])
use admin or django shell to change the site
read more about the sites framework here
.
How Django uses the sites framework
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.
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
>>>
in your 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:
SITE_ID = 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
I'll just check and find out for you
EDIT:
I am fairly certain thats what I did to make it work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With