這是base.py檔案
from pathlib import path
BASE_DIR = Path(__file__).resolve().parent.parent.parent
SECRET_KEY = 'h@1l- Holla!!! This is something crazy, $2423$#@$#@E@e#R3e[')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
allowed_hosts = []
install_apps = []
# Typical django code...
MIDDLEWARE = [
# 典型的django代碼...'project.url'
TEMPLATES = [
# 典型的django代碼...。
]
WSGI_APPLICATION = 'project.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
auth_password_validators = [
# Typical django code....
]
STATIC_URL = '/static/'/span>
# 靜態設定。
staticfiles_dirs = [
BASE_DIR / 'static',
]
# 媒體設定 '/media/'/span>
MEDIA_ROOT = BASE_DIR / 'media'/span>
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'。
這就是production.py
from .base import *
import environ
import django_heroku
env = environ.Env(
DEBUG=(bool, False),
)
SECRET_KEY = 'lol'/span>
# 現在為了方便,我已經硬編碼了這些。
# 盡管有environ package,但我還是硬編碼了這些。
DEBUG = False[/span
ALLOWED_HOSTS = ['*'/span>]
MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware')
DATABASES['default']['CONN_MAX_AGE'] = 60。
STATIC_ROOT = BASE_DIR / 'staticfiles'] = '靜態檔案'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
# 激活Django-Heroku.
django_heroku.settings(locals()
我把原來的settings.py重命名為base.py,并擴展到production.py。并且還更新了manage.py、wsgi.py和asgi.py。
基本上是按照這個方法 -> https://simpleisbetterthancomplex.com/tips/2017/07/03/django-tip-20-working-with-multiple-settings-modules.html
對我來說,一切看起來都很好
終端的螢屏截圖 - 請求錯誤500這段代碼給出了服務器錯誤(500)。
問題不在ALLOWED_HOSTS,這是肯定的。
編輯:當我洗掉這行django_heroku.settings(locals())時,少數錯誤得到了解決,盡管媒體檔案仍然沒有被加載
許多人都面臨著同樣的問題,但還沒有得到適當的答案!
請幫助我解決這個問題。
編輯2:
[08/Sep/2021 22: 01:05] ERROR [django.request:224] 內部服務器錯誤。/
回溯(最近一次呼叫)。
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjangocorehandlersexception.py", 行 47, in internal
response = get_response(request)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjangocorehandlersase.py", 行 204, in _get_response
回應 = 回應.渲染()
檔案"C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplate
esponse.py",第105行,in render
self.content = self.rendered_content
檔案"C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplate
esponse.py",第83,in rendered_content
return template.render(context, self._request)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplateackendsdjango.py", 行 61, in render
return self.template.render(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatease.py", 行 170, in render
return self._render(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatease.py", 行 162, in _render
return self.nodelist.render(text)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatease.py", 行 938, in render
bit = node.render_annotated(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatease.py", 行 905, in render_annotated
return self.render(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplateloader_tags.py", 行 150, in render
return compiled_parent._render(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatease.py", 行 162, in _render
return self.nodelist.render(text)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatease.py", 行 938, in render
bit = node.render_annotated(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatease.py", 行 905, in render_annotated
return self.render(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatetagsstatic.py", 行 106, in render
url = self.url(context)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatetagsstatic.py", 行 103, inurl
return self.handle_simple(path)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjango emplatetagsstatic.py",行118,in handle_simple
return staticfiles_storage.url(path)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjangocontribstaticfilesstorage.py",行147,in url
return self._url(self.store_name, name, force)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjangocontribstaticfilesstorage.py", 行 126, in _url
hash_name = hashed_name_func(*args)
檔案 "C:UsersVaibhav.virtualenvsproject-nE60Z89-libsite-packagesdjangocontribstaticfilesstorage.py"/span>, 行 417, in stored_name
raise ValueError("missing staticfiles manifest entry for '%s'" % clean_name)
ValueError。缺少靜態檔案清單條目 for 'home/css/base.css'。
[08/Sep/2021 22:01:05] ERROR [django.server:161] "GET / HTTP/1.1" 500 145
[08/Sep/2021 22:01:05] 警告 [django.request:224] 未找到。/favicon.ico
[08/Sep/2021 22:01:05] 。警告 [django.server:161] "GET /favicon.ico HTTP/1.1" 404 179
uj5u.com熱心網友回復:
你可以用下面的方法將所有的錯誤記錄到檔案中,即使在DEBUG=False
Update: Try this.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
' filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse''formatters': {
'verbose': {
'format': '[contactor] %(levelname)s %(asctime)s %(message)s'。
},
},
'handlers'/span>: {
# 將所有的訊息發送到控制臺。
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler'。
},
# 發送資訊到syslog。
'syslog':{
'level':'INFO'。
'class': 'logging.handlers.SysLogHandler'。
'設施': SysLogHandler.LOG_LOCAL2,
'address': '/dev/log',
'formatter': 'verbose',
},
# Warning messages are sent to admin emails[/span]。
'mail_admins': {
'level': 'warning',
'過濾器': ['require_debug_false']。
'class': 'django.utils.log.AdminEmailHandler'。
},
# critical errors are logged to sentry.
'sentry': {
'level': 'ERROR',
'過濾器': ['require_debug_false']。
'class': 'raven.contrib.django.handlers.SentryHandler'。
},
},
'loggers': {
# This is the "catch all" logger.
'': {
'handlers'/span>: ['console'/span>, 'syslog'/span>, 'mail_admins'/span>, 'sentry'/span>]。
'level'。'DEBUG'。
'propagate': False。
},
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/319750.html
標籤:
上一篇:Discord機器人在生產中出現UnhandledPromiseRejectionWarning(HEROKU)
