我的django应用程序在本地开发服务器中运行。要在heroku中部署,我必须使用whitenoise来提供静态文件。该应用程序已成功部署,但现在当我将调试标志切换为False时,我在开发和生产服务器上都出现服务器端错误。
这是我的结论
local_settings.py
from decouple import config
import dj_database_url
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'name',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
}
}
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
import os
from decouple import config
import dj_database_url
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ['*']
# Application definition
DJANGO_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
]
THIRD_PARTY_APPS = [
'allauth',
'allauth.account',
]
OUR_APPS = [
'inventory',
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + OUR_APPS
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'IMS.urls'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static_collected")
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
urls.py
urlpatterns = [
url(r'^accounts/', include('allauth.urls')),
url(r'^', include('inventory.urls')),
url(r'^admin/', admin.site.urls),
]
handler404 = 'IMS.views.page_not_found'
handler500 = 'IMS.views.server_error'
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
这是详细配置
https://gist.github.com/MilanRgm/166cf9aea3f401a4afec2d34c6511ed9
我错过了什么或做错了什么?
答案 0 :(得分:0)