django和mod_wsgi的配置问题

Jim*_*mbo 5 python apache django mod-wsgi

我在使用mod_wsgi让django在apache 2.2上工作时遇到了问题.Django也安装了mod_wsgi.访问路径时我甚至可以看到404页面,我可以登录django admin.但是如果我想安装标记模块,我会收到以下错误:

 Traceback (most recent call last):
   File "setup.py", line 49, in <module>
  version_tuple = __import__('tagging').VERSION
   File "/home/jim/django-tagging/tagging/__init__.py", line 3, in <module>
  from tagging.managers import ModelTaggedItemManager, TagDescriptor
   File "/home/jim/django-tagging/tagging/managers.py", line 5, in <module>
  from django.contrib.contenttypes.models import ContentType
   File "/usr/lib/python2.5/site-packages/django/contrib/contenttypes/models.py", line 1, in <module>
  from django.db import models
   File "/usr/lib/python2.5/site-packages/django/db/__init__.py", line 10, in <module>
  if not settings.DATABASE_ENGINE:
   File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 269, in __getattr__
  self._setup()
   File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 40, in _setup
  self._wrapped = Settings(settings_module)
   File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 75, in __init__
  raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
 ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings
Run Code Online (Sandbox Code Playgroud)

我的httpd.conf:

 Alias /media/ /home/jim/django/mysite/media/

 <Directory /home/jim/django/mysite/media>
  Order deny,allow
  Allow from all
 </Directory>

 Alias /admin/media/ "/usr/lib/python2.5/site-packages/django/contrib/admin/media/"

 <Directory "/usr/lib/python2.5/site-packages/django/contrib/admin/media/">
  Order allow,deny
  Allow from all
 </Directory>

 WSGIScriptAlias /dj /home/jim/django/mysite/apache/django.wsgi

 <Directory /home/jim/django/mysite/apache>
  Order deny,allow
  Allow from all
 </Directory>
Run Code Online (Sandbox Code Playgroud)

我的django.wsgi:

import sys, os

sys.path.append('/home/jim/django')
sys.path.append('/home/jim/django/mysite')

os.chdir('/home/jim/django/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Run Code Online (Sandbox Code Playgroud)

我试着让这个工作几天,并在这里阅读了几个博客和答案,但没有任何效果.

编辑:

现在我尝试使用这篇博文,我的wsgi文件现在看起来像这样:

import sys
sys.path.insert(0, '/home/jim/django/mysite')
sys.path.insert(0, '/home/jim/django')

import settings

import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')

command.validate()

import django.conf
import django.utils

django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Run Code Online (Sandbox Code Playgroud)

管理员仍在工作,但是当我尝试安装标记模块时,我遇到了同样的错误.

Lak*_*sad 4

第一的,

  • 由于您的管理员可以正常工作,因此 wsgi 的设置很好。不要费心去改变/编辑它。

为了确保不是Apache/mod-wsgi设置问题,您可以从生产机器运行开发服务器

python manage.py runserver 0:8080
Run Code Online (Sandbox Code Playgroud)

然后将浏览器指向

http://yoursite.com:8080/
Run Code Online (Sandbox Code Playgroud)

您必须看到完全相同的行为。

然后,

为了调试这个问题:

  • 在服务器上的 python shell 上,尝试import tagging. 显然,从您的回溯来看,import tagging这是引发错误的地方,这就是无法导入设置的原因。

  • 然后,只需删除包含标记的包,并通过以下命令进行全新安装,它就知道如何安装包了。

sudo pip install django-tagging
Run Code Online (Sandbox Code Playgroud)