如何让apache支持python? 可以用django

如何让apache支持python? 可以用django

我按网上的教程配了一下,在运行时,出现以下错误

[Copy to clipboard] [ - ]
CODE:
MOD_PYTHON ERROR

ProcessId:      3104
Interpreter:    'py.com'

ServerName:     'py.com'
DocumentRoot:   'E:/Web/python/app/'

URI:            '/index.py'
Location:       None
Directory:      'E:/Web/python/app/'
Filename:       'E:/Web/python/app/index.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'app'

Traceback (most recent call last):

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1202, in _process_target
    module = import_module(module_name, path=path)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 304, in import_module
    return __import__(module_name, {}, {}, ['*'])

ImportError: No module named app

很郁闷,怎么样让APACHE支持Python呢? 怎么样用Django呢?

ImportError: No module named app

看样子是你模块没有加入到sys.path里去。

在httpd.conf里加:PythonPath "['e:/你的路径']+sys.path"

我在httpd里加上了

[Copy to clipboard] [ - ]
CODE:
LoadModule python_module modules/mod_python.so

Alias /python E:/Web/python/app

<Directory "E:/Web/python/app">
  AllowOverride FileInfo
  AddHandler mod_python .py
  PythonHandler app
  PythonDebug On
  PythonPath "['E:/Web/python/app']+sys.path"
</Directory>

错误还是那样..

PythonPath "['E:/Web/python']+sys.path"

改成这个试试
十分感谢楼上耐心帮助.

我还是又返回这个错误

[Copy to clipboard] [ - ]
CODE:
MOD_PYTHON ERROR

ProcessId:      6104
Interpreter:    'py.com'

ServerName:     'py.com'
DocumentRoot:   'E:/Web/python/app/'

URI:            '/index.py'
Location:       None
Directory:      'E:/Web/python/app/'
Filename:       'E:/Web/python/app/index.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'app'

Traceback (most recent call last):

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1202, in _process_target
    module = import_module(module_name, path=path)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 304, in import_module
    return __import__(module_name, {}, {}, ['*'])

ImportError: No module named app

期待limodou来回答了,他对django精通
不知道如何解决,但觉得是PythonPath的问题;
app目录有__init__.py不?
你的配置文件不对,参考下面的设置

QUOTE:
http://code.google.com/p/svnaccesspolicy/wiki/VirtualHost

VirtualHost  

Apache 虚拟主机配置

Introduction

Apache 虚拟主机配置文件片段
Details

#装载模块

LoadModules   python_module       modules/mod_python.so

#声明虚拟主机

NameVirtualHost 127.0.0.1:80

#定义虚拟主机

<VirtualHost 127.0.0.1:80>
<Location />
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE settings
    PythonDebug On
    PythonPath "['D:\\workspace\\mysite'] + sys.path"
</Location>
</VirtualHost>

# 注意 PythonPath 的设置,跟你的SetEnv是有关联的。如果使用mysite.settings,那么PythonPath 就是 D:\\workspace

你的location配置贴出来。是按官方文档做的吗? http://docs.djangoproject.com/en ... eployment-modpython