添加带有mod_fcgid的自定义Django应用程序时出现500错误

添加带有mod_fcgid的自定义Django应用程序时出现500错误,django,mod-fcgid,Django,Mod Fcgid,我一直在关注他们网站上的官方Django 1.3教程。当我将我的自定义应用程序(轮询)添加到settings.py中的INSTALLED\u APPS列表时,我的问题就出现了,比如: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contri

我一直在关注他们网站上的官方Django 1.3教程。当我将我的自定义应用程序(轮询)添加到
settings.py
中的
INSTALLED\u APPS
列表时,我的问题就出现了,比如:

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
和我的
url.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)),
)
import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "polls"))

你的应用程序是否在PYTHONPATH上?您可以通过以下方式在外壳中进行检查:

$ python manage.py shell
在外壳中,使用

> import sys
> print sys.path 
如果应用程序不在
PYTHONPATH
上,则可以使用project的
settings.py
添加它

settings.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)),
)
import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "polls"))

如果这不是问题所在,您是否也可以显示调用模板的URL.py和views.py部分?

遇到同样的问题,解决了,请在settings.py中尝试以下操作:

import sys
sys.path.insert(0, "/home/user/django_projects/myproject/")

从这里开始:

我打印sys.path时没有看到应用程序,这可能是个问题吗?为了以防万一,我发布了结果以及我的URL。py通过将app添加到
sys.path
,更新了上面的答案。谢谢,但仍然给了我相同的错误:(我会发布我的
views.py
,但是这是空的
PYTHONPATH上的所有应用程序都是空的吗?
mod\uwsgi
?我刚刚用
mod\uwsgi
在Django1.3上试用了你的代码,假设你没有对
settings.py
\uu init\uuuu.py
做任何其他更改,它就可以了。你有没有是否尝试删除
消息
静态文件
应用?