简体   繁体   English

重定向每个URL到500服务器错误Django

[英]redirecting every url to 500 server error django

my django application works in local development server. 我的django应用程序可在本地开发服务器上工作。 To deploy in heroku I had to use whitenoise for serving static files. 要在heroku中进行部署,我必须使用whitenoise来提供静态文件。 The app is deployed successfully but now when I switch debug flag to False, i get server side error on both development and production server. 该应用程序已成功部署,但是现在当我将debug标志切换为False时,在开发服务器和生产服务器上都收到服务器端错误。

This is my confiugration 这是我的事

local_settings.py 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 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)

Here is the configuration in detail 这是详细的配置

https://gist.github.com/MilanRgm/166cf9aea3f401a4afec2d34c6511ed9 https://gist.github.com/MilanRgm/166cf9aea3f401a4afec2d34c6511ed9

What have i missed or did wrong? 我错过或做错了什么?

I have seen this in AWS. 我已经在AWS中看到了这一点。 This normally happens to me when my settings.py doesn't include: 当我的settings.py不包含以下内容时,通常会发生这种情况:

ALLOWED_HOSTS = ['*']

Probably similar to other stackoverflow post 可能类似于其他stackoverflow帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM