Невозможно импортировать собственный модуль django с помощью fcgi
Я запускаю приложение django через fcgi в системе общего хостинга моей школы. Все работает изначально (стандартная стартовая страница показывает, когда я просматриваю каталог с 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
Два вопроса Во-первых, это похоже на ту же ошибку, что и эта, но я не могу понять, что добавить в мой 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 ответ
Есть ли
sys.path.insert(0, "/keone/Scripts/django/resume/")
Работа? Я предполагаю, что все работает нормально в runserver.Вы можете пройти в
outlog
а такжеerrlog
запустить fastcgi. http://code.djangoproject.com/browser/django/trunk/django/core/servers/fastcgi.py?rev=10345