免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 12653 | 回复: 5

apache + mod_python 的问题 [复制链接]

论坛徽章:
0
发表于 2006-08-08 01:08 |显示全部楼层
Debian 3.1
apache 1.3
python 2.3
libapache-mod_python2.3

httpd.conf:
  1. <Directory /var/www/test>
  2.         AddHandler mod_python .py
  3.         PythonHandler mptest
  4.         PythonDebug On
  5.     </Directory>
复制代码



/var/www/test/mptest.py:
  1. from mod_python import apache

  2.     def handler(req):
  3.         req.content_type = 'text/plain'
  4.         req.write("Hello World!")
  5.         return apache.OK

复制代码


我完全按照
http://modpython.org/live/current/doc-html/inst-testing.html
这个网站内的
可是为什么http://ip/test/mptest的时候,老是提示我下载还是打开这个文件,而不是hello world

论坛徽章:
0
发表于 2006-08-08 13:31 |显示全部楼层
我也出现了相同的问题,不知道怎么办?

论坛徽章:
0
发表于 2006-08-08 13:53 |显示全部楼层
mod_python模块,需要先在httpd.conf中load。
  1. LoadModule python_module libexec/mod_python.so
复制代码


修改httpd.conf之后,还需要重新启动Apache。

论坛徽章:
0
发表于 2006-08-08 16:30 |显示全部楼层

回复 3楼 OneZ 的帖子

我的问题:
操作系统是ubuntu 6.06
Apache 版本是1.3.34, mod_python is 2.7.10(用的是libapache-mod-python2.4包)
python 2.4.3
这些都是通过apt-get 来安装的。

web root 是在 /var/www.
我建立了 一个 test目录

在http.conf 配置如下:

<Directory /var/www/test>
AddHandler python-program .py
PythonHandler mptest
PythonDebug On
</Directory>

在 modules.conf 配置文件中,
已经有
LoadModule python_module /usr/lib/apache/1.3/mod_python


然后我建立mptest.py文件,
内容如下:

from mod_python import apache
def handler(req):
req.send_http_header()
req.write("Hello World!")
return apache.OK

浏览 http://127.0.0.l/test/mptest.py, 得到服务器内部错误!
日志如下:
make_obcallback():could not import mod_python.apache
make_obcallback():could not call init
........python_handler: make_obcallback returned no obCallBack!


我的系统是安装了python2.3 和python2.4,但python指向了python2.4
我直接运行 mptest.py,输出如下:

Traceback (most recent call last)
File "/var/www/test/mptest.py",line 1, in ?
from mod_python import apache
File "/usr/lib/python2.4/site-packages/mod_python/apache.py",line 55 in ?
import _apache
ImportError: No module named _apache

有人遇到想到的问题吗?

论坛徽章:
0
发表于 2006-08-10 12:33 |显示全部楼层
试一试
  1. sudo a2enmod mod_python
复制代码
激活mod_python后,重启Apache。

[ 本帖最后由 OneZ 于 2006-8-10 14:35 编辑 ]

论坛徽章:
0
发表于 2007-02-23 00:03 |显示全部楼层
该操作第一步装mod-python(当然apache+python是已经安装ok后了),然后在httpd.conf里加入load mod-python模块,在web目录里加上
AddHandler python-program .py #py解释器
PythonHandler mptest #启动的文件名mptest.py
PythonDebug On #诊断

from mod_python import apache

    def handler(req):
        req.content_type = 'text/plain'
        req.write("Hello World!")
        return apache.OK

重起apache,ok
访问:http://url/mptest.py
操作ok
有关信息可以去我的论坛看这个帖子:http://www.1213s.com/thread-1481-1-1.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP