我收到此错误
Traceback (most recent call last):
File "/home/<username>/flup/server/fcgi_base.py", line 558, in run
File "/home/<username>/flup/server/fcgi_base.py", line 1116, in handler
File "/home/<username>/python/django/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/home/<username>/python/django/django/core/handlers/base.py", line 73, in get_response
response = middleware_method(request)
File "/home/<username>/python/django/django/contrib/sessions/middleware.py", line 10, in process_request
engine = import_module(settings.SESSION_ENGINE)
File "/home/<username>/python/django/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/<username>/python/django/django/contrib/sessions/backends/db.py", line 2, in ?
from django.contrib.sessions.models import Session
File "/home/<username>/python/django/django/contrib/sessions/models.py", line 4, in ?
from django.db import models
File "/home/<username>/python/django/django/db/__init__.py", line 41, in ?
backend = load_backend(settings.DATABASE_ENGINE)
File "/home/<username>/python/django/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/home/<username>/python/django/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/<username>/python/django/django/db/backends/mysql/base.py", line 13, in ?
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
当我尝试在共享服务器上运行此脚本时
#!/usr/bin/python
import sys, os
sys.path.insert(0, "/home/<username>/python/django")
sys.path.insert(0, "/home/<username>/python/django/www") # projects directory
os.chdir("/home/<username>/python/django/www/<project>")
os.environ['DJANGO_SETTINGS_MODULE'] = "<project>.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
但是,几个小时前,我的网络主机刚刚为我安装了MySQLdb
。当我从shell运行python时,我可以导入MySQLdb
就好了。为什么这个脚本会报告它无法找到它?
答案 0 :(得分:2)
你在python路径上缺少python-mysql db驱动程序。 看看你是否可以找出WSGI正在看到的python路径......这可能与你在shell中遇到的不同
答案 1 :(得分:1)
您的settings.py中是否有错误的DATABASE_ENGINE设置?它应该是mysql而不是mysqldb。