无法使用fcgi导入自己的django模块

时间:2010-06-11 17:55:29

标签: django mod-fcgid

我在学校的共享主机系统上通过fcgi运行django应用程序。一切都工作最初(当我用index.fcgi查看目录时显示标准的起始页面)但是当我添加模块并尝试导入时,我收到以下错误。当我在本地机器上运行时,相同的代码可以正常工作。

[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: Traceback (most recent call last):
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/flup/server/fcgi_base.py", line 558, in run
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     protocolStatus, appStatus = self.server.handler(self)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/flup/server/fcgi_base.py", line 1116, in handler
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     result = self.application(environ, start_response)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     response = self.get_response(request)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 134, in get_response
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return self.handle_uncaught_exception(request, resolver, exc_info)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 154, in handle_uncaught_exception
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return debug.technical_500_response(request, *exc_info)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/views/debug.py", line 40, in technical_500_response
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     html = reporter.get_traceback_html()
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/views/debug.py", line 114, in get_traceback_html
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return t.render(c)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 178, in render
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return self.nodelist.render(context)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 779, in render
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     bits.append(self.render_node(node, context))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 81, in render_node
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     raise wrapped
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: TemplateSyntaxError: Caught an exception while rendering: No module named students
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: Original Traceback (most recent call last):
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 71, in render_node
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     result = node.render(context)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 87, in render
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     output = force_unicode(self.filter_expression.resolve(context))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 572, in resolve
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     new_obj = func(obj, *arg_vals)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/template/defaultfilters.py", line 687, in date
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return format(value, arg)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 269, in format
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return df.format(format_string)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 30, in format
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     pieces.append(force_unicode(getattr(self, piece)()))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 175, in r
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return self.format('D, j M Y H:i:s O')
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/dateformat.py", line 30, in format
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     pieces.append(force_unicode(getattr(self, piece)()))
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/encoding.py", line 71, in force_unicode
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     s = unicode(s)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/functional.py", line 201, in __unicode_cast
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return self.__func(*self.__args, **self.__kw)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 62, in ugettext
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return real_ugettext(message)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 286, in ugettext
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     return do_translate(message, 'ugettext')
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 276, in do_translate
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     _default = translation(settings.LANGUAGE_CODE)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 194, in translation
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     default_translation = _fetch(settings.LANGUAGE_CODE)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 180, in _fetch
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     app = import_module(appname)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:   File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr:     __import__(name)
[Fri Jun 11 04:45:30 2010] [warn] mod_fcgid: stderr: ImportError: No module named students

两个问题。一,它似乎与this相同,但我无法弄清楚要添加到我的pythonpath中的内容。这是我的index.fcgi的内容。我试着执行

sys.path.insert(0, "/keone/Scripts/django/resume/students")

但这没有帮助。

#!/usr/bin/env python
import sys, os, time, threading, django.utils.autoreload
sys.path.insert(0, "/keone/Scripts/django")
os.chdir("/keone/Scripts/django/resume")
os.environ['DJANGO_SETTINGS_MODULE'] = "resume.settings"

def reloader_thread():
  while True:
    if django.utils.autoreload.code_changed():
      os._exit(3)
    time.sleep(1)
t = threading.Thread(target=reloader_thread)
t.daemon = True
t.start()

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

二,如何更改fcgi文件以关闭标准输出和标准错误并将其重新打开到另一个文件?我必须得到一个系统管理员才能从主日志中获取一个片段,我不能始终如一地依赖它。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

  1. sys.path.insert(0, "/keone/Scripts/django/resume/")是否有效?我假设在runserver中一切正常。

  2. 您可以将outlogerrlog传递给runfastcgi。 http://code.djangoproject.com/browser/django/trunk/django/core/servers/fastcgi.py?rev=10345#L21