在MAMP上使用Python [英] Use Python on MAMP

查看:230
本文介绍了在MAMP上使用Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在慢慢地从PHP迁移到Python.特别是,当我在webdev/webdesign中工作时,我想使用以下代码使用Python显示基本的HTML页面:

I'm slowly migrating from PHP to Python. In particular, as I work in webdev/webdesign I would like to display a basic HTML page using Python, using the following code :

#!/usr/bin/python

print('<html><head></head><body>This is a test</body></html>')

同样,重点只是看它是否有效.在主机上以index.cgi的形式在线发送文件,我对显示文件内容没有任何问题.当我尝试在MAMP上安装WSGI模块时,或者只是为了使Python与其一起正常工作时,问题就开始了.当它转到localhost/index.cgi时,将显示文件内容而不是结果. 我已经阅读了六篇教程,但似乎都没用,我总是在某个点或另一个地方遇到问题.似乎是由于MAMP随附的Apache并不是以允许您向其添加模块的方式构建的(例如wsgi).

Again, the point is just to see if it works. Sending the file online on my host as index.cgi I've had no problem displaying the content of the file. The problems start when I try to install the WSGI module on MAMP, or just to make Python work in general with it. When It go to localhost/index.cgi the content of the file is displayed instead of its results. I've followed half a dozen tutorials and none seems to work, I always encounter a problem at one point or another. It seems to come from the fact that Apache that comes with MAMP isn't built in a way that lets you add modules to it (such as wsgi).

这也来自以下事实:我找不到有关如何在MAMP上安装Python的任何最新文章,这些文章的发布日期均为2008年或2009年,而旧版本的MAMP,Python和Macports.

This is also comes from the fact that I can't find any recent article on how to install Python on MAMP, they all either date from 2008 or 2009, with old versions of MAMP, Python and Macports.

有人可以指出我要执行的当前程序吗?

Can somebody points me to the current procedure to make this work ?

:找到本文我收集到的信息是,默认情况下,MAMP不处理MAMP/中cgi-bin/文件夹之外的CGI脚本.因此,我按照说明修改了Apache conf文件,现在它显然读取了.cgi文件,但上面显示的内容引发了错误500.代码是罪魁祸首还是MAMP的代码?

EDIT : Ok after finding this article I gathered that MAMP by default don't process CGI scripts outside of the cgi-bin/ folder in MAMP/. So I modified the Apache conf file as explained, it now apparently reads the .cgi file but throws an error 500 with the content shown above. Is the code the culprit or is it MAMP's ?

推荐答案

使其正常工作,问题在于在cgi-bin/文件夹之外缺少MAMP的CAMP的CGI解释(请参见原始文章)和缺少的标头:

Got it to work, the problem were the missing CGI interpretation of MAMP outside of the cgi-bin/ folder (see original post) and the missing headers :

print 'Content-type: text/html\n\n'

这篇关于在MAMP上使用Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆