Mac Web服务器上的Python [英] Python on Mac Web Server

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

问题描述

当前,我的机器上运行的是PHP和Perl.我要做的是运行Python网站(开发).我已经安装了Python.我在网上寻找实现此目的的方法,但是很遗憾,我无法运行在屏幕上打印"Hello World"的hello.py文件. (屏幕显示了源代码,并且在文件顶部有#!/usr/bin/python).我试图修改我的httpd.conf文件,但它使服务器崩溃,并且无法加载任何内容. (我遵循了本教程:如何设置Python脚本以在Apache 2.0中工作?) 要在Mac上成功运行Python网站,我需要做/更改什么?

Currently, I have PHP and Perl running fine on my machine. What I want to do is run Python websites (Development). I have Python installed. I looked online for ways of doing this, but unfortunately can't run my hello.py file that prints "Hello World" on the screen. (Screen shows the source code, and I have #!/usr/bin/python on the top of the file). I tried to modify my httpd.conf file but it crashed the server and nothing would load. (I followed this tutorial: How do you set up Python scripts to work in Apache 2.0?) What are the things I need to do/change to successfully run Python website on my Mac?

推荐答案

获得简单的"Hello,World!"的最简单方法脚本运行是为了对脚本进行cgi处理.基本上,您将修改httpd.conf并搜索"AddHandler cgi-script"行.在其末尾添加.py,使其看起来像这样:

The easiest way to get a simple "Hello, World!" script running is to enable cgi handling of the scripts. Basically you would modify your httpd.conf and search for an "AddHandler cgi-script" line. Add .py to the end of it so that it looks something like this:

AddHandler cgi-script .cgi .py

此外,您可能需要为该文件夹中的该文件类型启用cgi处理.

Also, you may need to enable cgi handling for that filetype in that folder.

<Location /some/path/*.py>
Options +ExecCGI
</Location>

最后,确保提供正确的内容类型和标题,然后显示内容:

Finally, make sure you're serving the right content type and headers and out comes your content:

print "Content-type: text/html\n\n"
print "<html>Hello world!</html>"

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

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