内部服务器错误heroku / django

时间:2015-04-19 11:54:49

标签: python django heroku

在将项目部署到heroku服务器之后,我在heroku django教程中进行了堆栈。 当我打开heroku时,我在网站上:内部服务器错误。

这是我的heroku日志:



2015-04-19T11:37:10.239891+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=secure-waters-8181.herokuapp.com request_id=6a5e44bf-4691-4207-9c8f-d2b18bf46a23 fwd="213.108.119.145" dyno=web.1 connect=2ms service=6ms status=500 bytes=244
2015-04-19T11:37:37.790381+00:00 heroku[router]: at=info method=GET path="/" host=secure-waters-8181.herokuapp.com request_id=25f8ea3a-a81d-45dd-a576-5ce58029b75e fwd="213.108.119.145" dyno=web.1 connect=0ms service=2ms status=500 bytes=244
2015-04-19T11:37:37.789336+00:00 app[web.1]: [2015-04-19 11:37:37 +0000] [9] [ERROR] Error handling request
2015-04-19T11:37:37.789341+00:00 app[web.1]: Traceback (most recent call last):
2015-04-19T11:37:37.789343+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 93, in handle
2015-04-19T11:37:37.789344+00:00 app[web.1]:     self.handle_request(listener, req, client, addr)
2015-04-19T11:37:37.789346+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 134, in handle_request
2015-04-19T11:37:37.789347+00:00 app[web.1]:     respiter = self.wsgi(environ, resp.start_response)
2015-04-19T11:37:37.789349+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/dj_static.py", line 83, in __call__
2015-04-19T11:37:37.789351+00:00 app[web.1]:     return self.application(environ, start_response)
2015-04-19T11:37:37.789354+00:00 app[web.1]:     self.load_middleware()
2015-04-19T11:37:37.789356+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 44, in load_middleware
2015-04-19T11:37:37.789353+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 168, in __call__
2015-04-19T11:37:37.789357+00:00 app[web.1]:     mw_class = import_string(middleware_path)
2015-04-19T11:37:37.789358+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/module_loading.py", line 26, in import_string
2015-04-19T11:37:37.789360+00:00 app[web.1]:     module = import_module(module_path)
2015-04-19T11:37:37.789361+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
2015-04-19T11:37:37.789362+00:00 app[web.1]:     __import__(name)
2015-04-19T11:37:37.789364+00:00 app[web.1]: ImportError: No module named security




这是我的settings.py:



# 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',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'hellodjango.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'hellodjango.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/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/1.8/howto/static-files/

STATIC_URL = '/static/'


# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)




我必须在数据库设置中更改某些内容,否则在进行教程时我会错过点击?我不知道要解决它...... (抱歉我的代码片格式,我不知道以不同的方式复制我的代码)

1 个答案:

答案 0 :(得分:1)

在settings.py的MIDDLEWARE_CLASSES中,你有'django.middleware.security.SecurityMiddleware',,这是Django 1.8中的新功能。要么确保Heroku使用Django 1.8,要么从MIDDLEWARE_CLASSES中删除该行。