0

我刚刚将我的第一个 django 应用程序部署到 Heroku 平台。我基本上遵循了本教程,只是我没有创建一个虚拟的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,
        },
    }
}
4

3 回答 3

0

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

(r'^home/', include('MAINPROJECT_NAME.APPNAME.urls'))
于 2012-06-18T03:57:49.660 回答
0

所以我发现错误是heroku在名为“app”而不是“主题”的文件夹中创建了应用程序。我尝试使用 heroku CLI 重命名应用程序

heroku apps:rename theme

但由于某种原因我仍然无法弄清楚,它给出了一个You do not have access to appname错误。因此,我只是将代码中包含 theme.foo 的每一部分更改为 app.foo。它奏效了。

于 2012-06-18T06:01:42.970 回答
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_APPSthemes用 . 表示s,但您的 ROOT_URLCONF 表示theme没有s. 尝试让它们同步..

于 2012-06-18T06:07:09.520 回答