Python未在apach上解释

2024-09-29 17:14:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将Python设置为在mac上的本地apache服务器上运行。在

httpd.conf上,我已经

<VirtualHost *:80>
    DocumentRoot "/Users/ptamzz/Sites/python/sandbox.ptamzz.com"
    <Directory "/Users/pritams/Sites/python/sandbox.ptamzz.com">
        Options Indexes FollowSymLinks MultiViews ExecCGI
        AddHandler cgi-script .py
        Require all granted
    </Directory>
    DirectoryIndex index.py
    ServerName sandbox.ptamzz.com
    ErrorLog "/var/log/apache2/error-log"
    CustomLog "/var/log/apache2/access-log" common
</VirtualHost>

在我的文档根目录上,我的index.py文件是

^{pr2}$

但是当我在浏览器上加载页面时,python代码会按原样返回。 Screenshot

我错过了什么?在


Tags: py服务器comlogindexvarmacapache
1条回答
网友
1楼 · 发布于 2024-09-29 17:14:00

在Apache(cgi)中执行python

系统:OSX yosmite 10.10.3,默认apache

在http配置中取消注释

LoadModule cgi_module libexec/apache2/mod_cgi.so

虚拟主机条目

^{pr2}$

索引.py文件

#!/usr/bin/env python 
print "Content-type: text/html" 
print 
print "<html><body>Test Page</body></html>"

文件已使用

chmod a+x index.py

重新启动apache并输出

python in apache

相关问题 更多 >

    热门问题