簡體   English   中英

服務器錯誤 (500) 在部署 Heroku 的 Django 項目時出現密碼重置請求

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

我已經在 Heroku https://billpayy.herokuapp.com/上部署了我的 Django 項目。 當我嘗試重置密碼時,它會顯示錯誤 500 頁面。 密碼重置功能在本地運行良好,但在部署時會出現此錯誤。 此外,無法從錯誤日志中解碼太多:

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"

設置.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())

網址.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')
]

請幫我解決一下這個。

解決了。 問題出在我的 Google 帳戶的 DisplayUnclockCaptcha 設置上。 啟用它,對我來說一切正常。 通過將 DEBUG 設置為 True 來獲得線索。

3檢查確保。

  1. 確保在此處為您要發送密碼恢復電子郵件的電子郵件帳戶提供了較不安全的應用程序訪問權限。

  2. 與 DisplayUnlockCaptcha 有關的附加步驟。 確保在此處啟用。

  3. 打開您的 Gmail 帳戶 -> 設置 -> 查看所有設置 -> 轉發和 POP/IMAP -> 啟用 IMAP。

上述解決方案確實對我有用。

暫無
暫無

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

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