0

私は彼らのウェブサイトで公式の Django 1.3 チュートリアルに従っています。私の問題は、次のようにカスタム アプリ (投票) をINSTALLED_APPSリストに追加したときに発生しsettings.pyます。

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

ただし、戻ってスタック トレースを見ると、次のようになります。

mod_fcgid: stderr: TemplateSyntaxError: Caught ImportError while rendering: No module named polls

私は何を間違っていますか?スタック トレース全体を次に示します。

[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: Traceback (most recent call last):
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "build/bdist.linux-i686/egg/flup/server/fcgi_base.py", line 574, in run
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "build/bdist.linux-i686/egg/flup/server/fcgi_base.py", line 1159, in handler
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: response = self.get_response(request)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 169, in get_response
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 203, in handle_uncaught_exception
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return debug.technical_500_response(request, *exc_info)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/views/debug.py", line 59, in technical_500_response
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: html = reporter.get_traceback_html()
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/views/debug.py", line 151, in get_traceback_html
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return t.render(c)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/template/base.py", line 123, in render
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return self._render(context)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/template/base.py", line 117, in _render
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return self.nodelist.render(context)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/template/base.py", line 744, in render
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: bits.append(self.render_node(node, context))
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/template/debug.py", line 73, in render_node
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: result = node.render(context)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/template/debug.py", line 90, in render
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: output = self.filter_expression.resolve(context)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/template/base.py", line 536, in resolve
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: new_obj = func(obj, *arg_vals)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/template/defaultfilters.py", line 695, in date
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return format(value, arg)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/dateformat.py", line 285, in format
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return df.format(format_string)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/dateformat.py", line 30, in format
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: pieces.append(force_unicode(getattr(self, piece)()))
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/dateformat.py", line 191, in r
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return self.format('D, j M Y H:i:s O')
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/dateformat.py", line 30, in format
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: pieces.append(force_unicode(getattr(self, piece)()))
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/encoding.py", line 71, in force_unicode
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: s = unicode(s)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 206, in __unicode_cast
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return self.__func(*self.__args, **self.__kw)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/translation/__init__.py", line 81, in ugettext
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return _trans.ugettext(message)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 286, in ugettext
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: return do_translate(message, 'ugettext')
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 276, in do_translate
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: _default = translation(settings.LANGUAGE_CODE)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 185, in translation
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: default_translation = _fetch(settings.LANGUAGE_CODE)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/translation/trans_real.py", line 162, in _fetch
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: app = import_module(appname)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: File "/usr/lib/python2.4/site-packages/django/utils/importlib.py", line 35, in import_module
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: __import__(name)
[Sat Aug 04 07:16:55 2012] [warn] [client 74.202.255.243] mod_fcgid: stderr: TemplateSyntaxError: Caught ImportError while rendering: No module named polls

編集...ここに私のsys.path

/home/andydefo/andydeforest
/usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/setuptools-0.6c12dev_r88846-py2.4.egg
/usr/lib/python2.4/site-packages/flup-1.0.3.dev_20110405-py2.4.egg
/usr/lib/python2.4/site-packages/pip-1.1-py2.4.egg
/usr/lib/python24.zip
/usr/lib/python2.4
/usr/lib/python2.4/plat-linux2
/usr/lib/python2.4/lib-tk
/usr/lib/python2.4/lib-dynload
/usr/lib/python2.4/site-packages
/usr/lib/python2.4/site-packages/Numeric
/usr/lib/python2.4/site-packages/gtk-2.0

そして私のurls.py

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'andydeforest.views.home', name='home'),
    # url(r'^andydeforest/', include('andydeforest.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)
4

2 に答える 2

1

あなたのアプリは上にありPYTHONPATHますか?シェルで確認できます

$ python manage.py shell

シェルで、を使用して確認します

> import sys
> print sys.path 

アプリがオンPYTHONPATHになっていない場合は、プロジェクトのを使用して追加できますsettings.py

settings.py

import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "polls"))

それが問題ではない場合は、テンプレートが呼び出されている場所のurls.pyとviews.pyの部分も表示できますか?

于 2012-08-06T18:59:00.680 に答える