【问题标题】:django-allauth: how to modify email confirmation url?django-allauth:如何修改电子邮件确认 url?
【发布时间】:2014-07-30 11:23:36
【问题描述】:
我在端口 8001 上运行 django,而 nginx 在端口 80 上处理网络服务器职责。nginx 代理视图和对 Django 的一些 REST api 调用。我正在使用 django-allauth 进行用户注册/身份验证。
当新用户注册时,django-allauth 会向用户发送一封电子邮件,其中包含可供点击的链接。因为 django 在 8001 端口上运行,所以链接看起来像 http://machine-hostname:8001/accounts/confirm-email/xxxxxxxxxxxxxx
如何使网址看起来像http://www.example.com/accounts/confirm-email/xxxxxxxx?
谢谢!
【问题讨论】:
标签:
python
django
email
nginx
django-allauth
【解决方案1】:
Django 从 HTTP 标头中获取主机名和端口。
在选项proxy_pass 之前将proxy_set_header Host $http_host; 添加到您的nginx 配置中。
【解决方案2】:
我遇到了同样的问题,还发现 ferrangb 的解决方案对传出的 allauth 电子邮件没有影响。 mr_tron 的回答让我半途而废,但我不得不做更多的事情:
1) 在nginx配置中,放
proxy_set_header Host $http_host
在选项 proxy_pass 之前。
2) 在settings.py中,将域名添加到ALLOWED_HOSTS。我还添加了我的域名的 www 版本,因为这两个地址都获得了流量。
ALLOWED_HOSTS = ['127.0.0.1', 'example.com', 'www.example.com']
当然,重新启动 nginx 和 gunicorn 或任何为您的 Django 服务的东西。第一步但不是第二步,所有对站点的点击都是即时 400 错误(除非 DEBUG = True 在 settings.py。)