服务器错误(500)Django/Heroku加载主页时,但使用Django/admin工作正常



当我到达https://secure-brook-21764.herokuapp.com/admin/然后网站工作正常,但主屏幕

https://secure-brook-21764.herokuapp.com/

它给了我服务器错误500,加载静态文件有问题吗?

我想我的设置有问题。py

如何解决这个问题我检查了django部署到Heroku:服务器错误(500(这个问题,但它很旧,不能帮助我解决这个问题。设置.py

"""
Django settings for backend project.
Generated by 'django-admin startproject' using Django 3.1.4.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
import environ #import environ
env = environ.Env() # Initialise environment variables
environ.Env.read_env()
from datetime import timedelta
from pathlib import Path
import django_heroku
# 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.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []

# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'storages',
'base.apps.BaseConfig',
'blog.apps.BlogConfig',

'panel.apps.PanelConfig',
'sitebranding.apps.SitebrandingConfig',
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
}

SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=30),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': True,
'UPDATE_LAST_LOGIN': False,
'ALGORITHM': 'HS256',
'VERIFYING_KEY': None,
'AUDIENCE': None,
'ISSUER': None,
'AUTH_HEADER_TYPES': ('Bearer',),
'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',
'JTI_CLAIM': 'jti',
'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
}
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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',
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

ROOT_URLCONF = 'backend.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'frontend/build')
],
'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 = 'backend.wsgi.application'


#Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': env('DATABASE_ENGINE'),
'NAME': env('DATABASE_NAME'),
'USER': env('DATABASE_USER'),
'PASSWORD': env('DATABASE_PASS'),
'HOST': env('DATABASE_HOST'),
'PORT': env('DATABASE_PORT'),
}
}

# Password validation
# https://docs.djangoproject.com/en/3.1/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.1/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.1/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/images/'
STATICFILES_DIRS = [
BASE_DIR / 'static',
BASE_DIR / 'frontend/build/static'
]

MEDIA_ROOT = BASE_DIR / 'static/images'
STATIC_ROOT = BASE_DIR / 'staticfiles'
CORS_ALLOW_ALL_ORIGINS = True

django_heroku.settings(locals())

heroku日志

»   Warning: heroku update available from 7.53.0 to 7.54.1.
2021-07-13T19:23:50.174095+00:00 app[web.1]: /app/.heroku/python/lib/python3.9/site-packages/environ/environ.py:628: UserWarning: /app/backend/.env doesn't exist - if you're not configuring your environment separately, create one.
2021-07-13T19:23:50.174096+00:00 app[web.1]: warnings.warn(
2021-07-13T19:23:55.109966+00:00 heroku[router]: at=info method=GET path="/" host=secure-brook-21764.herokuapp.com request_id=72c2f1aa-4dc4-49c3-8dbc-2f88c835e939 fwd="111.119.187.35" dyno=web.1 connect=0ms service=6711ms status=500 bytes=411 protocol=https
2021-07-13T19:23:55.110445+00:00 app[web.1]: 10.16.235.227 - - [13/Jul/2021:19:23:55 +0000] "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"
2021-07-13T19:23:59.347995+00:00 heroku[router]: at=info method=GET path="/" host=secure-brook-21764.herokuapp.com request_id=f374009d-6dd1-40ad-9ca2-a58a07381469 fwd="111.119.187.35" dyno=web.1 connect=1ms service=99ms status=500 bytes=411 protocol=https
2021-07-13T19:23:59.348062+00:00 app[web.1]: 10.63.55.157 - - [13/Jul/2021:19:23:59 +0000] "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"
2021-07-13T19:27:04.440886+00:00 app[web.1]: 10.63.104.194 - - [13/Jul/2021:19:27:04 +0000] "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"
2021-07-13T19:27:04.442849+00:00 heroku[router]: at=info method=GET path="/" host=secure-brook-21764.herokuapp.com request_id=dbcba227-40ba-4c2e-9582-8ef1546e73a0 fwd="111.119.187.35" dyno=web.1 connect=2ms service=647ms status=500 bytes=411 protocol=https
2021-07-13T19:36:40.937007+00:00 heroku[router]: at=info method=GET path="/admin/" host=secure-brook-21764.herokuapp.com request_id=9e13e831-57e6-4937-9267-ed7102a56224 fwd="111.119.187.35" dyno=web.1 connect=1ms service=695ms status=200 bytes=11281 protocol=https
2021-07-13T19:36:40.950361+00:00 app[web.1]: 10.16.206.21 - - [13/Jul/2021:19:36:40 +0000] "GET /admin/ HTTP/1.1" 200 10905 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"
2021-07-13T19:36:41.942237+00:00 app[web.1]: 10.16.188.46 - - [13/Jul/2021:19:36:41 +0000] "GET /admin/ HTTP/1.1" 200 10905 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"
2021-07-13T19:36:41.942519+00:00 heroku[router]: at=info method=GET path="/admin/" host=secure-brook-21764.herokuapp.com request_id=1754ec3a-e76e-41ce-821f-c85d82081415 fwd="111.119.187.35" dyno=web.1 connect=1ms service=456ms status=200 bytes=11281 protocol=https
2021-07-13T19:41:27.294356+00:00 heroku[router]: at=info method=GET path="/" host=secure-brook-21764.herokuapp.com request_id=86b778bf-1f73-47f4-ac70-4ec7b9010552 fwd="18.215.158.31" 
dyno=web.1 connect=2ms service=70ms status=500 bytes=411 protocol=https
2021-07-13T19:41:27.294668+00:00 app[web.1]: 10.41.182.161 - - [13/Jul/2021:19:41:27 +0000] "GET / HTTP/1.1" 500 145 "-" "Go-http-client/1.1"
2021-07-13T19:41:27.390831+00:00 heroku[router]: at=info method=GET path="/admin/" host=secure-brook-21764.herokuapp.com request_id=3f345e76-7773-46d5-9bdb-cc6394217532 fwd="18.215.158.31" dyno=web.1 connect=4ms service=37ms status=302 bytes=413 protocol=https
2021-07-13T19:41:27.395623+00:00 app[web.1]: 10.69.232.207 - - [13/Jul/2021:19:41:27 +0000] "GET /admin/ HTTP/1.1" 302 0 "-" "Go-http-client/1.1"
2021-07-13T19:41:30.797540+00:00 app[web.1]: 10.61.245.89 - - [13/Jul/2021:19:41:30 +0000] "GET / HTTP/1.1" 500 145 "-" "Go-http-client/1.1"
2021-07-13T19:41:30.798322+00:00 heroku[router]: at=info method=GET path="/" host=secure-brook-21764.herokuapp.com request_id=3e0857d0-6eaf-44f5-97e8-ec60053e8578 fwd="18.215.158.31" 
dyno=web.1 connect=1ms service=48ms status=500 bytes=411 protocol=https
2021-07-13T19:41:33.291468+00:00 app[web.1]: 10.45.27.72 - - [13/Jul/2021:19:41:33 +0000] "GET /admin/ HTTP/1.1" 302 0 "-" "Go-http-client/1.1"
2021-07-13T19:41:33.291841+00:00 heroku[router]: at=info method=GET path="/admin/" host=secure-brook-21764.herokuapp.com request_id=1de6bbcc-56c2-4bdd-a29f-8dc07b24696e fwd="18.215.158.31" dyno=web.1 connect=0ms service=5ms status=302 bytes=413 protocol=https
2021-07-13T19:42:04.540701+00:00 app[web.1]: 10.45.246.133 - - [13/Jul/2021:19:42:04 +0000] "HEAD /admin/ HTTP/1.1" 302 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36"
2021-07-13T19:42:04.549206+00:00 heroku[router]: at=info method=HEAD path="/admin/" host=secure-brook-21764.herokuapp.com request_id=39d50e66-769b-4c9d-8203-a80bfa5f6aab fwd="217.182.175.162" dyno=web.1 connect=3ms service=24ms status=302 bytes=413 protocol=https
2021-07-13T19:42:04.651523+00:00 app[web.1]: 10.43.193.55 - - [13/Jul/2021:19:42:04 +0000] "HEAD / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36"
2021-07-13T19:42:04.656164+00:00 heroku[router]: at=info method=HEAD path="/" host=secure-brook-21764.herokuapp.com request_id=79af7784-d0bd-4986-90fd-25f4013e478f fwd="217.182.175.162" dyno=web.1 connect=1ms service=131ms status=500 bytes=411 protocol=https
2021-07-13T19:42:04.769524+00:00 app[web.1]: 10.45.246.133 - - [13/Jul/2021:19:42:04 +0000] "HEAD /admin/login/?next=/admin/ HTTP/1.1" 200 2279 "-" "Mozilla/5.0 (Macintosh; Intel Mac 
OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36"
2021-07-13T19:42:04.770051+00:00 heroku[router]: at=info method=HEAD path="/admin/login/?next=/admin/" host=secure-brook-21764.herokuapp.com request_id=e443f5be-7723-49d0-a714-f7390ef6c1be fwd="217.182.175.162" dyno=web.1 connect=0ms service=132ms status=200 bytes=542 protocol=https
2021-07-13T19:43:00.038659+00:00 app[web.1]: 10.63.104.194 - - [13/Jul/2021:19:43:00 +0000] "GET /admin/ HTTP/1.1" 200 10905 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"
2021-07-13T19:43:00.038876+00:00 heroku[router]: at=info method=GET path="/admin/" host=secure-brook-21764.herokuapp.com request_id=3f7df71c-a83c-4236-84e3-c0ff2dd4b5aa fwd="111.119.187.35" dyno=web.1 connect=1ms service=108ms status=200 bytes=11281 protocol=https
2021-07-13T19:43:04.806650+00:00 app[web.1]: 10.63.104.194 - - 

您可以检查Heroku日志,此错误大多发生在views.py或任何其他python文件中。

相关内容

  • 没有找到相关文章

最新更新