您如何设置 Python 脚本以在 Apache 2.0 中工作? [英] How do you set up Python scripts to work in Apache 2.0?

查看:19
本文介绍了您如何设置 Python 脚本以在 Apache 2.0 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照一些关于设置 mod_python 的 google 搜索教程进行操作,但每次都失败了.你有一个很好的、循序渐进、坚如磐石的操作方法吗?

I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?

我的开发箱是 OS X,生产环境 - Centos.

My dev box is OS X, production - Centos.

推荐答案

在 Apache 上运行 Python 有两种主要方式.最简单的方法是使用 CGI 并编写普通的 Python 脚本,而第二种方法是使用 Django 或 Pylons 等网络框架.

There are two main ways of running Python on Apache. The simplest would be to use CGI and write normal Python scripts while the second is using a web framework like Django or Pylons.

使用 CGI 很简单.确保您的 Apache 配置文件设置了 cgi-bin.如果没有,请按照他们的文档(http://httpd.apache.org/docs/2.0/howto/cgi.html).此时,您需要做的就是将 Python 脚本放在 cgi-bin 目录中,标准输出将成为 HTTP 响应.有关更多信息,请参阅 Python 文档(https://docs.python.org/library/cgi.html).

Using CGI is straightforward. Make sure your Apache config file has a cgi-bin set up. If not, follow their documentation (http://httpd.apache.org/docs/2.0/howto/cgi.html). At that point all you need to do is place your Python scripts in the cgi-bin directory and the standard output will become the HTTP response. Refer to Python's documentation for further info (https://docs.python.org/library/cgi.html).

如果您想使用网络框架,您需要设置 mod_python 或 FastCGI.这些步骤取决于您要使用的框架.Django 提供了关于如何使用 Apache 设置 mod_python 和 Django 的明确说明(http://www.djangoproject.com/documentation/modpython/)

If you want to use a web framework you'll need to setup mod_python or FastCGI. These steps are dependent on which framework you want to use. Django provides clear instructions on how to setup mod_python and Django with Apache (http://www.djangoproject.com/documentation/modpython/)

这篇关于您如何设置 Python 脚本以在 Apache 2.0 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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