django 密码重置在服务器上不起作用,但在本地计算机上起作用

django password reset does not work on server but works on local machine

我正在使用 gmail 密码管理器生成密码。当我尝试发送电子邮件以在服务器上重置密码时,我收到 500 错误。当我尝试在本地发送密码重置电子邮件时,同样的格式有效。

这些是我在 settings.py

中的设置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = config['EMAIL_USER']
EMAIL_HOST_PASSWORD = config['EMAIL_PASS']
DEFAULT_FROM_EMAIL = config['EMAIL_USER']

我什至尝试过对电子邮件和密码进行硬编码,但仍然行不通。

我正在使用 apache2,这是我的配置:

src => 所有项目文件,recipe_app => 项目设置

src
|__recipe_app
   |__settings.py
   |__wsgi.py
Alias /static /home/<user>/src/static
<Directory /home/<user>/src/static>
    Require all granted
</Directory>

Alias /media /home/<user>/src/media
<Directory /home/<user>/src/media>
    Require all granted
</Directory>

<Directory /home/<user>/src/recipe_app>
    <Files wsgi.py>
        Require all granted
</Files>
</Directory>

WSGIScriptAlias / /home/<user>/src/recipe_app/wsgi.py
WSGIDaemonProcess recipe_app python-path=/home/<user>/src python-home=/home/<user>/src/venv
WSGIProcessGroup recipe_app

编辑: 来自 /var/log/apache2/error.log

的错误
[Sun Nov 15 17:11:13.398934 2020] [wsgi:error] [pid 59359:tid 140426823104064] [remote 73.24.24.160:51419] Not Found: /favicon.ico
[Sun Nov 15 17:15:39.443147 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421] Internal Server Error: /password-reset/
[Sun Nov 15 17:15:39.443217 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421] Traceback (most recent call last):
[Sun Nov 15 17:15:39.443224 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
[Sun Nov 15 17:15:39.443229 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     response = get_response(request)
[Sun Nov 15 17:15:39.443233 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
[Sun Nov 15 17:15:39.443237 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Sun Nov 15 17:15:39.443241 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
[Sun Nov 15 17:15:39.443245 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return self.dispatch(request, *args, **kwargs)
[Sun Nov 15 17:15:39.443249 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
[Sun Nov 15 17:15:39.443253 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return bound_method(*args, **kwargs)
[Sun Nov 15 17:15:39.443257 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
[Sun Nov 15 17:15:39.443261 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     response = view_func(request, *args, **kwargs)
[Sun Nov 15 17:15:39.443264 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/views.py", line 222, in dispatch
[Sun Nov 15 17:15:39.443279 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return super().dispatch(*args, **kwargs)
[Sun Nov 15 17:15:39.443283 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
[Sun Nov 15 17:15:39.443287 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return handler(request, *args, **kwargs)
[Sun Nov 15 17:15:39.443290 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/views/generic/edit.py", line 142, in post
[Sun Nov 15 17:15:39.443294 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return self.form_valid(form)
[Sun Nov 15 17:15:39.443297 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/views.py", line 235, in form_valid
[Sun Nov 15 17:15:39.443301 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     form.save(**opts)
[Sun Nov 15 17:15:39.443304 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 323, in save
[Sun Nov 15 17:15:39.443308 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     self.send_mail(
[Sun Nov 15 17:15:39.443311 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 273, in send_mail
[Sun Nov 15 17:15:39.443315 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     email_message.send()
[Sun Nov 15 17:15:39.443318 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/mail/message.py", line 284, in send
[Sun Nov 15 17:15:39.443322 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return self.get_connection(fail_silently).send_messages([self])
[Sun Nov 15 17:15:39.443326 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
[Sun Nov 15 17:15:39.443330 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     new_conn_created = self.open()
[Sun Nov 15 17:15:39.443333 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 62, in open
[Sun Nov 15 17:15:39.443337 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     self.connection = self.connection_class(self.host, self.port, **connection_params)
[Sun Nov 15 17:15:39.443340 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py", line 253, in __init__
[Sun Nov 15 17:15:39.443340 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py">
[Sun Nov 15 17:15:39.443344 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     (code, msg) = self.connect(host, post, port)
[Sun Nov 15 17:15:39.443347 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py", line 339, in connect
[Sun Nov 15 17:15:39.443351 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     self.sock = self._get_socket(host, port, self.timeout)
[Sun Nov 15 17:15:39.443354 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py", line 308, in _get_socket
[Sun Nov 15 17:15:39.443358 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return socket.create_connection((host, port), timeout,
[Sun Nov 15 17:15:39.443365 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/socket.py", line 808, in create_connection
[Sun Nov 15 17:15:39.443369 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     raise err
[Sun Nov 15 17:15:39.443372 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/socket.py", line 796, in create_connection
[Sun Nov 15 17:15:39.443376 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     sock.connect(sa)
[Sun Nov 15 17:15:39.443379 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421] TimeoutError: [Errno 110] Connection timed out
[Sun Nov 15 17:26:36.683349 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51528] Not Found: /favicon.ico
[Sun Nov 15 17:27:04.919592 2020] [core:warn] [pid 59358:tid 140426973744448] AH00045: child process 59360 still did not exit, sending a SIGTERM
[Sun Nov 15 17:27:06.594680 2020] [wsgi:error] [pid 59360:tid 140426740708928] [client 73.24.24.160:51525] Truncated or oversized response headers received from daemon process 'recipe_app': /home/<user>/src/recipe_app/wsgi.py, referer: https://www.myawesomerecipeapp.com/password-reseet/

端口状态: ports

原来Linode因为垃圾邮件而屏蔽了邮件服务,所以你必须打开工单才能启用邮件功能。这是来源:source