没有名为theme.urls的模块

时间:2012-06-18 03:40:00

标签: django heroku

我刚刚将我的第一个django应用程序部署到了Heroku平台。我基本上遵循this tutorial,而不是创建一个虚拟的django-admin.py startproject hellodjango . django应用程序,我使用了我的应用程序,目前可以在我的Windows PC上运行。部署应用程序并在heroku上运行服务器时,我得到No module named theme.urls

这是追溯。有什么想法吗?

Environment:


Request Method: GET
Request URL: http://severe-winter-1546.herokuapp.com/

Django Version: 1.4
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'themes',
 'haystack')
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')


Traceback:
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  298.             for pattern in self.url_patterns:
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  328.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  323.             self._urlconf_module = import_module(self.urlconf_name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: ImportError at /
Exception Value: No module named theme.urls

我的settings.py

# Django settings for theme project.
import os
import dj_database_url
ROOT_PATH = os.path.dirname(__file__)
DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}

LANGUAGE_CODE = 'en-us'

SITE_ID = 1


USE_I18N = True


USE_L10N = True


MEDIA_ROOT = os.path.join(ROOT_PATH, 'files')


MEDIA_URL = 'http://127.0.0.1:8000/files/'


STATIC_ROOT = ''


STATIC_URL = '/static/'


ADMIN_MEDIA_PREFIX = '/static/admin/'


STATICFILES_DIRS = (
)


STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.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',
)

ROOT_URLCONF = 'theme.urls'

TEMPLATE_DIRS = (
'C:/Users/leonsas/Desktop/dj/theme/templates',
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #'registration',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'themes',
    'haystack',

)
#required for haystack. Using Whoosh
HAYSTACK_WHOOSH_PATH = 'C:/Users/leonsas/Desktop/dj/theme/files/Whoosh/index'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_SITECONF = 'theme.search_sites'



LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

3 个答案:

答案 0 :(得分:0)

主项目的urls.py设置错误,这是我可以从异常跟踪中推断出来的。请在主项目urls.py中使用下面提到的内容。

(r'^home/', include('MAINPROJECT_NAME.APPNAME.urls'))

答案 1 :(得分:0)

所以我发现错误是heroku在名为'app'而不是'theme'的文件夹中创建了应用程序。我尝试使用

通过heroku CLI重命名应用程序
heroku apps:rename theme

但由于某些原因我无法弄清楚,它给出了You do not have access to appname错误。所以我只是将我的代码的每个部分都改为app.foo。它起作用了。

答案 2 :(得分:0)

在我看来,你已经错误地命名了一些东西。查看ROOT_URLCONF和INSTALLED_APPS:

ROOT_URLCONF = 'theme.urls'
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #'registration',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'themes',
    'haystack',
)

您的INSTALLED_APPS说themes s,但您的ROOT_URLCONF说theme而没有s。尝试让它们同步..