我知道已经回答了很多 Django ImportErrors 但我尝试了他们所有的解决方案都无济于事!
背景:我正在尝试使用 A Small Orange 在共享主机上设置 Wagtail(Django 变体)。由于 ASO 规范,我运行 python 2.6 + virtualenv + FastCGI
我的项目目录在:
~/username/website/wagtailweb
我的 pip_installed 包和所有相关的符号链接都在:
~/.env/lib/python2.6/site-packages
当我访问我的域时,我在 / Traceback 处收到 Django 的导入错误:
Environment:
Request Method: GET
Request URL: http://username.co/
Django Version: 1.6.2
Python Version: 2.6.6
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'compressor',
'taggit',
'modelcluster',
'django.contrib.admin',
'wagtail.wagtail.wagtailcore',
'wagtail.wagtail.wagtailadmin',
'wagtail.wagtail.wagtaildocs',
'wagtail.wagtail.wagtailsnippets',
'wagtail.wagtail.wagtailusers',
'wagtail.wagtail.wagtailimages',
'wagtail.wagtail.wagtailembeds',
'wagtail.wagtail.wagtailsearch',
'wagtail.wagtail.wagtailredirects',
'tutorial')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'wagtail.wagtail.wagtailcore.middleware.SiteMiddleware',
'wagtail.wagtail.wagtailredirects.middleware.RedirectMiddleware')
Traceback:
File "/home/username/.env/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
101. resolver_match = resolver.resolve(request.path_info)
File "/home/username/.env/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
320. sub_match = pattern.resolve(new_path)
File "/home/username/.env/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
320. sub_match = pattern.resolve(new_path)
File "/home/username/.env/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
222. return ResolverMatch(self.callback, args, kwargs, self.name)
File "/home/username/.env/lib/python2.6/site-packages/django/core/urlresolvers.py" in callback
229. self._callback = get_callable(self._callback_str)
File "/home/username/.env/lib/python2.6/site-packages/django/utils/functional.py" in wrapper
32. result = func(*args)
File "/home/username/.env/lib/python2.6/site-packages/django/core/urlresolvers.py" in get_callable
100. not module_has_submodule(import_module(parentmod), submod)):
File "/home/username/.env/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
41. __import__(name)
Exception Type: ImportError at /
Exception Value: No module named wagtailcore
我的设置.py
# Django settings for wagtailweb project.
import os
PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..', '..')
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = ()
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': PROJECT_ROOT+'/wagtailweb.db',
'HOST': '', # Set to empty string for localhost.
'PORT': '', # Set to empty string for default.
}
}
CONN_MAX_AGE = 600 # number of seconds database connections should persist for
ALLOWED_HOSTS = []
TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-gb'
SITE_ID = 1
USE_I18N = True
USE_L10N = False
USE_TZ = True
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'wagtail.wagtail.wagtailcore.middleware.SiteMiddleware',
'wagtail.wagtail.wagtailredirects.middleware.RedirectMiddleware',
)
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.request',
)
ROOT_URLCONF = 'wagtailweb.urls'
TEMPLATE_DIRS = ()
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
# 'django.contrib.sites', # Wagtail uses its own site management logic
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'compressor',
'taggit',
'modelcluster',
'django.contrib.admin',
'wagtail.wagtail.wagtailcore',
'wagtail.wagtail.wagtailadmin',
'wagtail.wagtail.wagtaildocs',
'wagtail.wagtail.wagtailsnippets',
'wagtail.wagtail.wagtailusers',
'wagtail.wagtail.wagtailimages',
'wagtail.wagtail.wagtailembeds',
'wagtail.wagtail.wagtailsearch',
'wagtail.wagtail.wagtailredirects',
'tutorial',
)
EMAIL_SUBJECT_PREFIX = '[wagtailweb] '
INTERNAL_IPS = ('127.0.0.1', '10.0.2.2')
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)
# Auth settings
LOGIN_URL = 'django.contrib.auth.views.login'
LOGIN_REDIRECT_URL = 'wagtailadmin_home'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
# WAGTAIL SETTINGS
WAGTAIL_SITE_NAME = 'wagtailweb'
# Override the search results template for wagtailsearch
WAGTAILSEARCH_RESULTS_TEMPLATE = 'tutorial/search_results.html'
WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'tutorial/includes/search_listing.html'
WAGTAILSEARCH_ES_INDEX = 'wagtailweb'
我的网址.py
import os
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.views.generic.base import RedirectView
from django.contrib import admin
from django.conf import settings
from wagtail.wagtail.wagtailcore import urls as wagtail_urls
from wagtail.wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtail.wagtailimages import urls as wagtailimages_urls
from wagtail.wagtail.wagtailembeds import urls as wagtailembeds_urls
from wagtail.wagtail.wagtaildocs import admin_urls as wagtaildocs_admin_urls
from wagtail.wagtail.wagtaildocs import urls as wagtaildocs_urls
from wagtail.wagtail.wagtailsnippets import urls as wagtailsnippets_urls
from wagtail.wagtail.wagtailsearch.urls import frontend as wagtailsearch_frontend_urls, admin as wagtailsearch_admin_urls
from wagtail.wagtail.wagtailusers import urls as wagtailusers_urls
from wagtail.wagtail.wagtailredirects import urls as wagtailredirects_urls
admin.autodiscover()
# Signal handlers
from wagtail.wagtail.wagtailsearch import register_signal_handlers as wagtailsearch_register_signal_handlers
wagtailsearch_register_signal_handlers()
urlpatterns = patterns('',
url(r'^django-admin/', include(admin.site.urls)),
url(r'^admin/images/', include(wagtailimages_urls)),
url(r'^admin/embeds/', include(wagtailembeds_urls)),
url(r'^admin/documents/', include(wagtaildocs_admin_urls)),
url(r'^admin/snippets/', include(wagtailsnippets_urls)),
url(r'^admin/search/', include(wagtailsearch_admin_urls)),
url(r'^admin/users/', include(wagtailusers_urls)),
url(r'^admin/redirects/', include(wagtailredirects_urls)),
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^search/', include(wagtailsearch_frontend_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
# For anything not caught by a more specific rule above, hand over to
# Wagtail's serving mechanism
url(r'', include(wagtail_urls)),
)
if settings.DEBUG:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns() # tell gunicorn where static files are in dev mode
urlpatterns += static(settings.MEDIA_URL + 'images/', document_root=os.path.join(settings.MEDIA_ROOT, 'images'))
Wagtailcore 是我安装的 Wagtail 应用程序中的一个模块。它确实有自己的 init.py 并且位于 python sys 路径上。
所有的回溯都指向 Django,我不愿意摆弄他们的代码。这一定是我的结果,但不幸的是,我没有足够的知识来弄清楚是什么原因造成的。