发生服务器错误。请联系管理员

时间:2014-12-09 15:14:46

标签: python django macos python-2.7 django-models

我正在开发Django(python)中的web应用程序。它在过去几天工作正常,但后来我开始使用django开发另一个应用程序。现在,当我运行服务器时切换到旧的应用程序开发,我收到一个错误:“发生服务器错误。请联系管理员。”

来自终端的追溯:

File "/Users/somdipdey/anaconda/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 168, in __call__
    self.load_middleware()
  File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py", line 44, in load_middleware
    mw_class = import_string(middleware_path)
  File "/Users/somdipdey/anaconda/lib/python2.7/site-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/Users/somdipdey/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named security

设置文件:

"""
Django settings for SteanneWebsite project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^ay$t!hm-4fm4!)ppxoc!$j1^p1b&kiv+*s&3eox^k*bh$er^8'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_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',
    'News',
    'Messages',
)

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',
    'django.contrib.admin',
)

ROOT_URLCONF = 'SteanneWebsite.urls'

WSGI_APPLICATION = 'SteanneWebsite.wsgi.application'


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

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

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

STATIC_URL = '/static/'

#Template Location
TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(BASE_DIR), "static", "templates"),
)

1 个答案:

答案 0 :(得分:2)

SecurityMiddleware是Django开发版中的新功能,并且在发布的1.7中不可用。如果你真的想使用它,你应该切换到开发头,但我不建议从dev运行生产站点。您应该只是在中间件设置中删除对它的引用。