0

我的 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' 

网址.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

我错过了什么或做错了什么?

4

1 回答 1

0

我在 AWS 中看到了这一点。当我的 settings.py 不包括时,这通常会发生在我身上:

ALLOWED_HOSTS = ['*']

可能类似于其他stackoverflow帖子

于 2017-11-21T06:38:23.170 回答