Mod_wsgi 语法错误:“无效的命令导入”

0 投票
1 回答
1677 浏览
提问于 2025-04-16 21:30

我正在尝试设置mod_wsgi来服务我的Django媒体文件(我也想在开发环境中使用这个)。

我按照这个指南来正确设置mod_wsgi。

这是我的wsgi文件("django.wsgi")

import os, sys

path = '/home/smau/Workspace/Maynard/tothego_frontend/'
if path not in sys.path:
    sys.path.append(path)

#Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)

os.environ['DJANGO_SETTINGS_MODULE'] = 'tothego_frontend.settings' 

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

这是我的配置文件("django.conf")

Alias /site_media/ "/home/smau/Workspace/Maynard/tothego_frontend/site_media/"
<Directory "/home/smau/Workspace/Maynard/tothego_frontend/site_media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>

WSGIScriptAlias / "/home/smau/Workspace/Maynard/tothego_frontend/srv/mod_wsgi/django.wsgi"

<Directory "/home/smau/Workspace/Maynard/tothego_frontend/srv/mod_wsgi">
Allow from all
</Directory>

这是我的" httpd.conf "

Include /home/smau/Workspace/Maynard/tothego_frontend/srv/mod_wsgi/django.wsgi

一切看起来都和指南一致,但是,当我尝试启动或重启Apache时,出现了这个错误

root@archimedes:/etc/apache2# /etc/init.d/apache2 restart
Syntax error on line 1 of /home/smau/Workspace/Maynard/tothego_frontend/srv/mod_wsgi/django.wsgi:
Invalid command 'import', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
   ...fail!

这是/var/log/apache2.log

[Thu Jul 14 11:39:31 2011] [notice] Apache/2.2.17 (Ubuntu) PHP/5.3.5-1ubuntu7.2 
with Suhosin-Patch mod_wsgi/3.3 Python/2.7.1+ configured -- resuming normal operations

[Thu Jul 14 11:44:28 2011] [notice] caught SIGTERM, shutting down
PHP Warning:  PHP Startup: Unable to load dynamic library 
'/usr/lib/php5/20090626/gd.so'- /usr/lib/php5/20090626/gd.so: cannot open shared object file: 
No such file or directory in Unknown on line 0

日志似乎(在我看来……)和我的问题没有关系。为什么我总是遇到“导入”错误?我给的信息够吗,还是你需要其他的?我想我的python路径是正确的:

1 个回答

2

你应该包含配置文件(django.conf),而不是WSGI脚本(django.wsgi)。

撰写回答