简体   繁体   中英

django-oscar error ( A server error occurred. Please contact the administrator)?

Iam create project in django-oscar with the help of http://django-oscar.readthedocs.org/en/latest/internals/getting_started.html tutorial ,

i installed every packages which they mention in doc . after i run my project i getting (A server error occurred. Please contact the administrator. this error in ui) and the error throwing in terminal is

  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 168, in __call__
    self.load_middleware()
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 44, in load_middleware
    mw_class = import_string(middleware_path)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/apps/basket/middleware.py", line 8, in <module>
    Applicator = get_class('offer.utils', 'Applicator')
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 67, in get_class
    return get_classes(module_label, [classname])[0]
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 124, in get_classes
    oscar_module = _import_module(oscar_module_label, classnames)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 159, in _import_module
    return __import__(module_label, fromlist=classnames)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/apps/offer/utils.py", line 10, in <module>
    ConditionalOffer = get_model('offer', 'ConditionalOffer')
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 321, in get_model
    return apps.get_model(app_label, model_name)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/apps/registry.py", line 202, in get_model
    return self.get_app_config(app_label).get_model(model_name.lower())
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/apps/registry.py", line 150, in get_app_config
    raise LookupError("No installed app with label '%s'." % app_label)
LookupError: No installed app with label 'offer'.
[23/Mar/2015 07:22:20] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 168, in __call__
    self.load_middleware()
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 44, in load_middleware
    mw_class = import_string(middleware_path)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/apps/basket/middleware.py", line 8, in <module>
    Applicator = get_class('offer.utils', 'Applicator')
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 67, in get_class
    return get_classes(module_label, [classname])[0]
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 124, in get_classes
    oscar_module = _import_module(oscar_module_label, classnames)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 159, in _import_module
    return __import__(module_label, fromlist=classnames)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/apps/offer/utils.py", line 10, in <module>
    ConditionalOffer = get_model('offer', 'ConditionalOffer')
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/oscar/core/loading.py", line 321, in get_model
    return apps.get_model(app_label, model_name)
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/apps/registry.py", line 202, in get_model
    return self.get_app_config(app_label).get_model(model_name.lower())
  File "/home/spericorn/global/oscar/local/lib/python2.7/site-packages/django/apps/registry.py", line 150, in get_app_config
    raise LookupError("No installed app with label '%s'." % app_label)
LookupError: No installed app with label 'offer'.

my settings.py is :

""" Django settings for frobshop project.

""

from oscar.defaults import *
from oscar import OSCAR_MAIN_TEMPLATE_DIR
import os
def root(x):
    return os.path.join(os.path.abspath(os.path.dirname(__file__)), '..',x)


SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
     'compressor',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'oscar.apps.basket.middleware.BasketMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
)


AUTHENTICATION_BACKENDS = (
    'oscar.apps.customer.auth_backends.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

ROOT_URLCONF = 'frobshop.urls'

WSGI_APPLICATION = 'frobshop.wsgi.application'


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': root( 'db.sqlite3'),
        'ATOMIC_REQUESTS': True,
    }
}

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

SITE_ID = 1

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.request",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    'oscar.apps.search.context_processors.search_form',
    'oscar.apps.promotions.context_processors.promotions',
    'oscar.apps.checkout.context_processors.checkout',
    'oscar.apps.customer.notifications.context_processors.notifications',
    'oscar.core.context_processors.metadata',
)


MEDIA_ROOT = root('media')

MEDIA_URL = '/media/'

STATIC_ROOT = root('staticstorage')

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    root('static'),
)

TEMPLATE_DIRS = [
    root('templates'),
    OSCAR_MAIN_TEMPLATE_DIR
]

#
# HAYSTACK_CONNECTIONS = {
#     'default': {
#         'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
#         'URL': 'http://127.0.0.1:8983/solr',
#         'INCLUDE_SPELLING': True,
#     },
# }

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}

Thanks in advance,please help me.

Try this

from oscar import get_core_apps


INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
     'compressor',
] + get_core_apps()

get_core_apps will include

OSCAR_CORE_APPS = [
    'oscar',
    'oscar.apps.analytics',
    'oscar.apps.checkout',
    'oscar.apps.address',
    'oscar.apps.shipping',
    'oscar.apps.catalogue',
    'oscar.apps.catalogue.reviews',
    'oscar.apps.partner',
    'oscar.apps.basket',
    'oscar.apps.payment',
    'oscar.apps.offer',
    'oscar.apps.order',
    'oscar.apps.customer',
    'oscar.apps.promotions',
    'oscar.apps.search',
    'oscar.apps.voucher',
    'oscar.apps.wishlists',
    'oscar.apps.dashboard',
    'oscar.apps.dashboard.reports',
    'oscar.apps.dashboard.users',
    'oscar.apps.dashboard.orders',
    'oscar.apps.dashboard.promotions',
    'oscar.apps.dashboard.catalogue',
    'oscar.apps.dashboard.offers',
    'oscar.apps.dashboard.partners',
    'oscar.apps.dashboard.pages',
    'oscar.apps.dashboard.ranges',
    'oscar.apps.dashboard.reviews',
    'oscar.apps.dashboard.vouchers',
    'oscar.apps.dashboard.communications',
    # 3rd-party apps that oscar depends on
    'haystack',
    'treebeard',
    'sorl.thumbnail',
    'django_tables2',
]

You dont import Oscar core apps. You need to import them and add to the INSTALLED_APPS. You can doing this by importing from oscar import get_core_apps

get_core_apps is a function that return (list) a default and required Oscar core apps. So you need to concatenate it.

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
     'compressor',
] + get_core_apps()

Note: If your INSTALLED_APPS is a tuple (not list) you got a error, because get_core_apps() return a list. So you need to change your INSTALLED_APPS to a list type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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