简体   繁体   中英

Django specifying password reset email subject

I have setup my django application to use the built in auth.views to reset password. The problem is that this is what the message looks like:

Subject: Password reset on 127.0.0.1:8001

You're receiving this email because you requested a password reset for your user account at 127.0.0.1:8001.

Please go to the following page and choose a new password:

http://127.0.0.1:8001/accounts/reset/MQ/4j3-d83f7cdb7f0203afe85e/

Your username, in case you've forgotten: myuser

Thanks for using our site!

The 127.0.0.1:8001 team

It seems like it's pulling localhost from the gunicorn deployment. I have it set up so that nginx routes the domain @port 80 to localhost at port 8001. How do I go about changing this to have " http://mydomain/accounts/reset ...." instead?

Seems like people are downvoting this because it isn't specific enough. Here's what I have set up:

url(r'^resetpassword/passwordsent/$', password_reset_done, {'template_name': 'password_recovery/recover_password_sent.html'}, name='password_reset_done'),
url(r'^resetpassword/$', password_reset, {'template_name': 'password_recovery/recover_password.html'}, name='password_reset'),

These urls are pulling from django.contrib.auth.views . And it seems like {{ domain }} variable is what they're using to construct the email. The problem is, it's pulling localhost as my domain since the gunicorn daemon is binding it to localhost at port 8001. How would I go about modifying it so that I get the actual domain, is there a variable in settings.py?

I think you have just go to admin and configure your site to http://mydomain , because domain variable in the reset template is taken from there:

in view:

    current_site = get_current_site(request)
    site_name = current_site.name
    domain = current_site.domain

in template:

{% autoescape off %}{% load usertools %}Hi {{user|display_name}},

You're receiving this email because you requested a password reset for your user account at {{domain}}.

Your username: {{user.get_username}}

Please go to the following page and choose a new password:

{{protocol}}://{{domain}}{% url 'password_reset_confirm' uidb64=uid token=token %}

If clicking isn't working for you, simply paste the URL into your favorite web browser.

See you soon!{% endautoescape %}

It looks like it's getting the site name from the Site object, or if it's not available then from request.META .

https://docs.djangoproject.com/en/1.10/topics/auth/default/#django.contrib.auth.views.password_reset

So configuring a Site object could fix this for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM