模块'oscar'没有属性'OSCAR_MAIN_TEMPLATE_DIR'

时间:2017-10-24 16:46:45

标签: python django heroku django-oscar

我尝试在heroku上部署我的django-oscar应用程序,但是当我运行迁移时:heroku运行sandbox / manage.py migrate

发生以下错误:(使用的数据库是postgresql,我安装了所有要求,但我不知道问题的根源)

2017-10-24T16:02:49.121254+00:00 heroku[run.8440]: Starting process with     command `sandbox/manage.py migrate`
2017-10-24T16:02:49.731452+00:00 heroku[run.8440]: State changed from     starting to up
2017-10-24T16:02:52.721398+00:00 heroku[run.8440]: State changed from up to complete
2017-10-24T16:02:52.595920+00:00 app[run.8440]: Traceback (most recent call last):
2017-10-24T16:02:52.595939+00:00 app[run.8440]:   File "sandbox/manage.py", line 10, in <module>
2017-10-24T16:02:52.596126+00:00 app[run.8440]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in     execute_from_command_line
2017-10-24T16:02:52.596124+00:00 app[run.8440]:     execute_from_command_line(sys.argv)
2017-10-24T16:02:52.596439+00:00 app[run.8440]:     utility.execute()
2017-10-24T16:02:52.596734+00:00 app[run.8440]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
2017-10-24T16:02:52.596730+00:00 app[run.8440]:     settings.INSTALLED_APPS
2017-10-24T16:02:52.597070+00:00 app[run.8440]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
2017-10-24T16:02:52.596912+00:00 app[run.8440]:     self._setup(name)
2017-10-24T16:02:52.597067+00:00 app[run.8440]:     self._wrapped = Settings(settings_module)
2017-10-24T16:02:52.596915+00:00 app[run.8440]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
2017-10-24T16:02:52.597249+00:00 app[run.8440]:     mod = importlib.import_module(self.SETTINGS_MODULE)
2017-10-24T16:02:52.597438+00:00 app[run.8440]:     return _bootstrap._gcd_import(name[level:], package, level)
2017-10-24T16:02:52.597622+00:00 app[run.8440]:   File "<frozen importlib._bootstrap>", line 961, in _find_and_load
2017-10-24T16:02:52.597996+00:00 app[run.8440]:   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2017-10-24T16:02:52.597748+00:00 app[run.8440]:   File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
2017-10-24T16:02:52.598147+00:00 app[run.8440]:   File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
2017-10-24T16:02:52.597443+00:00 app[run.8440]:   File "<frozen importlib._bootstrap>", line 978, in _gcd_import
2017-10-24T16:02:52.597878+00:00 app[run.8440]:   File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
2017-10-24T16:02:52.597253+00:00 app[run.8440]:   File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2017-10-24T16:02:52.596444+00:00 app[run.8440]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 307, in execute
2017-10-24T16:02:52.598467+00:00 app[run.8440]: AttributeError: module 'oscar' has no attribute 'OSCAR_MAIN_TEMPLATE_DIR'
2017-10-24T16:02:52.598446+00:00 app[run.8440]:     oscar.OSCAR_MAIN_TEMPLATE_DIR,
2017-10-24T16:02:52.598271+00:00 app[run.8440]:   File "/app/sandbox/settings.py", line 110, in <module>

在settings.py中,这是oscar.OSCAR_MAIN_TEMPLATE_DIR存在的地方:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        location('templates'),
        oscar.OSCAR_MAIN_TEMPLATE_DIR,
    ],
    'OPTIONS': {
        'loaders': [
            'django.template.loaders.filesystem.Loader',
            'django.template.loaders.app_directories.Loader',
            'django.template.loaders.eggs.Loader',
        ],
        'context_processors': [
            'django.contrib.auth.context_processors.auth',
            'django.template.context_processors.request',
            'django.template.context_processors.debug',
            'django.template.context_processors.i18n',
            'django.template.context_processors.media',
            'django.template.context_processors.static',
            'django.contrib.messages.context_processors.messages',

            # Oscar specific
            'oscar.apps.search.context_processors.search_form',
            'oscar.apps.customer.notifications.context_processors.notifications',
            'oscar.apps.promotions.context_processors.promotions',
            'oscar.apps.checkout.context_processors.checkout',
            'oscar.core.context_processors.metadata',
        ],
        'debug': DEBUG,
    }
}

edit1:Django == 1.11.3 django-oscar == 1.5 setting.py文件:

import os
import environ
import oscar

env = environ.Env()

# Path helper
location = lambda x: os.path.join(
    os.path.dirname(os.path.realpath(__file__)), x)

DEBUG = env.bool('DEBUG', default=False, cast=bool)
SQL_DEBUG = DEBUG

ALLOWED_HOSTS = [
    '127.0.0.1', 'localhost',
]

# This is needed for the hosted version of the sandbox
ADMINS = (
    ('David Winterbottom', 'david.winterbottom@gmail.com'),
    ('Michael van Tellingen', 'michaelvantellingen@gmail.com'),
)
EMAIL_SUBJECT_PREFIX = '[sandbox] '
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

MANAGERS = ADMINS

# Use a Sqlite database by default
DATABASES = {
    'default': dj_database_url.config(
        default=config('DATABASE_URL')
    )
}

CACHES = {
    'default': env.cache(default='locmemcache://'),
}


# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
USE_TZ = True
TIME_ZONE = 'Europe/London'

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-gb'

# Includes all languages that have >50% coverage in Transifex
# Taken from Django's default setting for LANGUAGES
gettext_noop = lambda s: s
LANGUAGES = (
    ('ar', gettext_noop('Arabic')),
    ('fr', gettext_noop('French')),
    ('en', gettext_noop('English')),
)

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = location("public/media")

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'

STATIC_URL = '/static/'
STATIC_ROOT = location('public/static')
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' ##
STATICFILES_DIRS = (
    location('static/'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

SECRET_KEY = '$)a7n&o80u!6y5t-+jrd3)3!%vh&shg$wqpjpxc!ar&p#!)n1a'
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            location('templates'),
            oscar.OSCAR_MAIN_TEMPLATE_DIR,
        ],
        'OPTIONS': {
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'django.template.loaders.eggs.Loader',
            ],
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.request',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.contrib.messages.context_processors.messages',

                # Oscar specific
                'oscar.apps.search.context_processors.search_form',
                'oscar.apps.customer.notifications.context_processors.notifications',
                'oscar.apps.promotions.context_processors.promotions',
                'oscar.apps.checkout.context_processors.checkout',
                'oscar.core.context_processors.metadata',
            ],
            'debug': DEBUG,
        }
    }
]



MIDDLEWARE = [
    'debug_toolbar.middleware.DebugToolbarMiddleware',

    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',

    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',

    # Allow languages to be selected
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.http.ConditionalGetMiddleware',
    'django.middleware.common.CommonMiddleware',

    # Ensure a valid basket is added to the request instance for every request
    'oscar.apps.basket.middleware.BasketMiddleware',
]

ROOT_URLCONF = 'urls'


# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(message)s',
        },
        'simple': {
            'format': '[%(asctime)s] %(message)s'
        },
    },
    'root': {
        'level': 'DEBUG',
        'handlers': ['console'],
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
    },
    'loggers': {
        'oscar': {
            'level': 'DEBUG',
            'propagate': True,
        },
        'oscar.catalogue.import': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': False,
        },
        'oscar.alerts': {
            'handlers': ['null'],
            'level': 'INFO',
            'propagate': False,
        },

        # Django loggers
        'django': {
            'handlers': ['null'],
            'propagate': True,
            'level': 'INFO',
        },
        'django.request': {
            'handlers': ['console'],
            'level': 'ERROR',
            'propagate': True,
        },
        'django.db.backends': {
            'level': 'WARNING',
            'propagate': True,
        },
        'django.security.DisallowedHost': {
            'handlers': ['null'],
            'propagate': False,
        },

        # Third party
        'raven': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'sorl.thumbnail': {
            'handlers': ['console'],
            'propagate': True,
            'level': 'INFO',
        },
    }
}


INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.flatpages',
    'django.contrib.staticfiles',
    'django.contrib.sitemaps',
    'django_extensions',

    # Debug toolbar + extensions
    'debug_toolbar',
    'apps.gateway',     # For allowing dashboard access
    'widget_tweaks',
] + oscar.get_core_apps()

# Add Oscar's custom auth backend so users can sign in using their email
# address.
AUTHENTICATION_BACKENDS = (
    'oscar.apps.customer.auth_backends.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        'OPTIONS': {
            'min_length': 9,
        }
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
]

LOGIN_REDIRECT_URL = '/'
APPEND_SLASH = True

# ====================
# Messages contrib app
# ====================

from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
    messages.ERROR: 'danger'
}

# Haystack settings
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': location('whoosh_index'),
    },
}
# Here's a sample Haystack config if using Solr (which is recommended)
#HAYSTACK_CONNECTIONS = {
#    'default': {
#        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
#        'URL': u'http://127.0.0.1:8983/solr/oscar_latest/',
#        'INCLUDE_SPELLING': True
#    },
#}

# =============
# Debug Toolbar
# =============

INTERNAL_IPS = ['127.0.0.1', '::1']

# ==============
# Oscar settings
# ==============

from oscar.defaults import *

# Meta
# ====

OSCAR_SHOP_TAGLINE = 'Sandbox'

OSCAR_RECENTLY_VIEWED_PRODUCTS = 20
OSCAR_ALLOW_ANON_CHECKOUT = True

# This is added to each template context by the core context processor.  It is
# useful for test/stage/qa sites where you want to show the version of the site
# in the page title.
DISPLAY_VERSION = False


# Order processing
# ================

# Sample order/line status settings. This is quite simplistic. It's like you'll
# want to override the set_status method on the order object to do more
# sophisticated things.
OSCAR_INITIAL_ORDER_STATUS = 'Pending'
OSCAR_INITIAL_LINE_STATUS = 'Pending'

# This dict defines the new order statuses than an order can move to
OSCAR_ORDER_STATUS_PIPELINE = {
    'Pending': ('Being processed', 'Cancelled',),
    'Being processed': ('Complete', 'Cancelled',),
    'Cancelled': (),
    'Complete': (),
}

# This dict defines the line statuses that will be set when an order's status
# is changed
OSCAR_ORDER_STATUS_CASCADE = {
    'Being processed': 'Being processed',
    'Cancelled': 'Cancelled',
    'Complete': 'Shipped',
}

# LESS/CSS
# ========

# We default to using CSS files, rather than the LESS files that generate them.
# If you want to develop Oscar's CSS, then set USE_LESS=True to enable the
# on-the-fly less processor.
USE_LESS = False


# Sentry
# ======

if env('SENTRY_DSN', default=None):
    RAVEN_CONFIG = {'dsn': env('SENTRY_DSN', default=None)}
    LOGGING['handlers']['sentry'] = {
        'level': 'ERROR',
        'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
    }
    LOGGING['root']['handlers'].append('sentry')
    INSTALLED_APPS.append('raven.contrib.django.raven_compat')


# Sorl
# ====
OSCAR_MISSING_IMAGE_URL = MEDIA_ROOT + '\image_not_found.jpg'

THUMBNAIL_DEBUG = DEBUG
THUMBNAIL_KEY_PREFIX = 'oscar-sandbox'
THUMBNAIL_KVSTORE = env(
    'THUMBNAIL_KVSTORE',
    default='sorl.thumbnail.kvstores.cached_db_kvstore.KVStore')
THUMBNAIL_REDIS_URL = env('THUMBNAIL_REDIS_URL', default=None)


# Django 1.6 has switched to JSON serializing for security reasons, but it does not
# serialize Models. We should resolve this by extending the
# django/core/serializers/json.Serializer to have the `dumps` function. Also
# in tests/config.py
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'

# Try and import local settings which can be used to override any of the above.
try:
    from settings_local import *
except ImportError:
    pass

0 个答案:

没有答案