簡體   English   中英

如何用正確的域替換電子郵件中的localhost來設置django重置密碼?

[英]How to replace localhost in emails with correct domain for django reset password?

我正在通過nginx為帶有反向代理的django應用程序提供服務。 該應用程序在本地localhost:8686下運行,該本地主機映射到example.com。 因此,重置密碼的正確鏈接類似於:

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)。

文件和來源:

  1. https://docs.djangoproject.com/zh-CN/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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM