我正在通过nginx提供带有反向代理的django应用程序。该应用程序在映射到 example.com 的 localhost:8686 下本地运行。因此,重置密码的正确链接如下所示:
https://example.com:8686/accounts/reset/MQ/591-05377c39db92f2d5368a/
但这是电子邮件中出现的内容:
https://localhost:8686/accounts/reset/MQ/591-05377c39db92f2d5368a/
显然,django(本地服务员(不知道域名。是否可以告诉 django 它应该使用哪个域名?
执行所需操作的第一种方法是通过创建自定义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 %}
另一种方法是启用"站点框架"(请参阅链接#2(。
文档和来源:
https://docs.djangoproject.com/en/2.2/topics/auth/default/#django.contrib.auth.views.PasswordResetView
https://docs.djangoproject.com/en/2.2/ref/contrib/sites/
https://github.com/django/django/blob/master/django/contrib/admin/templates/registration/password_reset_email.html
https://github.com/django/django/blob/1e429df748867097451bf0b45d1080ae6828d921/django/contrib/auth/forms.py#L277