0

I am serving a django app with a reverse proxy via nginx. The app runs locally under localhost:8686 which is mapped to example.com. So the correct link to reset a password would be something like:

https://example.com:8686/accounts/reset/MQ/591-05377c39db92f2d5368a/

but this is what appears in the emails:

https://localhost:8686/accounts/reset/MQ/591-05377c39db92f2d5368a/

Obviously, django (locally served with waitress) does not know about the domain name. Is it possible to tell django which domain name it should be using?

Soerendip
  • 7,684
  • 15
  • 61
  • 128

1 Answers1

1

First way to do what you want is by overriding the default template by creating a custom registration/password_reset_email.html:

{# yourProject/yourApp/templates/registration/password_reset_email.html #}
{% trans "Please go to the following page and choose a new password:" %}
{% block reset_link %}
{{ protocol }}://domain.com{% url 'password_reset_confirm' uidb64=uid token=token %}
{% endblock %}

Another way to do this is by enabling the "site framework" (see the link #2).

Docs and sources:

  1. https://docs.djangoproject.com/en/2.2/topics/auth/default/#django.contrib.auth.views.PasswordResetView

  2. https://docs.djangoproject.com/en/2.2/ref/contrib/sites/

  3. https://github.com/django/django/blob/master/django/contrib/admin/templates/registration/password_reset_email.html

  4. https://github.com/django/django/blob/1e429df748867097451bf0b45d1080ae6828d921/django/contrib/auth/forms.py#L277

Max Malysh
  • 29,384
  • 19
  • 111
  • 115