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

名前を間違えたようです。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。それらを同期させてみてください。

于 2012-06-18T06:07:09.520 に答える
0

メイン プロジェクトの urls.py の設定が間違っています。これは例外トレースから推測できます。メイン プロジェクトの urls.py では、以下のようなものを使用してください。

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

そのため、エラーは、heroku が「テーマ」ではなく「アプリ」という名前のフォルダーにアプリを作成したことであることがわかりました。を使用してheroku CLI経由でアプリの名前を変更しようとしました

heroku apps:rename theme

しかし、何らかの理由でまだ理解できず、You do not have access to appnameエラーが発生しました。その代わりに、コードの theme.foo を含むすべての部分を app.foo に変更しました。そしてそれはうまくいきました。

于 2012-06-18T06:01:42.970 に答える