简体   繁体   English

服务器错误 (500) 在部署 Heroku 的 Django 项目时出现密码重置请求

[英]Server Error (500) On Password Reset Request when deployed Django Project at Heroku

I have deployed my Django Project on Heroku https://billpayy.herokuapp.com/ .我已经在 Heroku https://billpayy.herokuapp.com/上部署了我的 Django 项目。 When I try to reset the password, it gives an Error 500 page.当我尝试重置密码时,它会显示错误 500 页面。 The Password Reset functionality works fine locally but gives this error when deployed.密码重置功能在本地运行良好,但在部署时会出现此错误。 Also, couldn't decode much from the Error Logs :此外,无法从错误日志中解码太多:

2021-05-30T12:08:10.012088+00:00 heroku[router]: at=info method=POST path="/account/password_reset/" host=billpayy.herokuapp.com requ
est_id=90b04f79-c813-4efa-8d2a-aa922d0bcae9 fwd="27.4.64.168" dyno=web.1 connect=4ms service=765ms status=500 bytes=403 protocol=http
2021-05-30T12:08:10.012273+00:00 app[web.1]: 10.30.51.66 - - [30/May/2021:12:08:10 +0000] "POST /account/password_reset/ HTTP/1.1" 50
0 145 "http://billpayy.herokuapp.com/account/password_reset/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, l
ike Gecko) Chrome/91.0.4472.77 Safari/537.36"

settings.py设置.py

"""
Django settings for billing_site project.

Generated by 'django-admin startproject' using Django 3.2.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os
import django_heroku
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['billpayy.herokuapp.com']


# Application definition

INSTALLED_APPS = [
    'billingapp.apps.BillingappConfig',
    'users.apps.UsersConfig',
    'bootstrap4',
    'crispy_forms',
    'bootstrap_datepicker_plus',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'billing_site.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'billing_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = 'site-home'

LOGIN_URL = 'site-sign-in'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')

django_heroku.settings(locals())

urls.py网址.py

from django.urls import path
from django.contrib.auth import views as auth_views
from . import views

urlpatterns = [
    path('', views.account, name='site-account'),
    path('register/', views.register, name='site-register'),
    path('sign_in/',
         auth_views.LoginView.as_view(template_name='users/sign_in.html'),
         name='site-sign-in'),
    path('log_out/',
         auth_views.LogoutView.as_view(template_name='users/log_out.html'),
         name='site-sign-out'),
    path('password_reset/',
         auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'),
         name='password_reset'),
    path('password_reset/done/',
         auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'),
         name='password_reset_done'),
    path('password_reset_confirm/<uidb64>/<token>/',
         auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'),
         name='password_reset_confirm'),
    path('password_reset_confirm/done/',
         auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'),
         name='password_reset_complete')
]

Please help me with this.请帮我解决一下这个。

Solved.解决了。 The problem was with DisplayUnclockCaptcha Settings for my Google Account.问题出在我的 Google 帐户的 DisplayUnclockCaptcha 设置上。 Enabled that and things worked fine for me.启用它,对我来说一切正常。 Got the clue by setting DEBUG to True.通过将 DEBUG 设置为 True 来获得线索。

3 checks to ensure. 3检查确保。

  1. Make Sure that the E-Mail Account from which you want to send Password Recovery Emails is given Less Secure App Access here .确保在此处为您要发送密码恢复电子邮件的电子邮件帐户提供了较不安全的应用程序访问权限。

  2. An Additional step that has something to do with DisplayUnlockCaptcha.与 DisplayUnlockCaptcha 有关的附加步骤。 Make sure that is enabled here .确保在此处启用。

  3. Open you Gmail account -> Settings -> See All Settings -> Forwarding and POP/IMAP -> Enable IMAP.打开您的 Gmail 帐户 -> 设置 -> 查看所有设置 -> 转发和 POP/IMAP -> 启用 IMAP。

The above solution did work for me.上述解决方案确实对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM