can't import own django module using fcgi
I'm running a django app through fcgi on my school's shared hosting system. Everything works initially (standard start page shows when I view the directory with index.fcgi) but when I add a module and try to import, I get the following error. The same code works when I run on my local machine.
[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 r开发者_运维百科esolve
[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
Two questions. One, it seems like the same error as this but I can't figure out what to add to my pythonpath. Here's the contents of my index.fcgi. I tried executing
sys.path.insert(0, "/keone/Scripts/django/resume/students")
but that didn't help.
#!/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")
Two, how do I change the fcgi file to close standard output and standard error and reopen them to a different file? I had to get a sysadmin to get a snippet out of the master log, and I can't count on this consistently.
Thanks for your help!
Does
sys.path.insert(0, "/keone/Scripts/django/resume/")
work? I assume everything is working fine in a runserver.You can pass in
outlog
anderrlog
to runfastcgi. http://code.djangoproject.com/browser/django/trunk/django/core/servers/fastcgi.py?rev=10345#L21
精彩评论