且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运行Python脚本像PHP

更新时间:2022-10-28 18:04:35

这看起来并不酷为具有WSGI应用程序的运行,所以我建议你使用的烧瓶框架这很简单,只要可以是一个明智的框架。

下面的描述上的mod_wsgi 安装程序的链接。

之后,你可能要考虑像Django的,金字塔,神交...

一个很酷的框架

如果你真的想使用mod_wsgi的喜欢mod_php的检查格雷厄姆邓普尔顿伟大的答案。

There are Apache 2 + mod_wsgi + Python 2.6 on server.

I would like to run scripts from Python like PHP scripts. The idea may seem silly, but I'm so accustomed (at least at first learning Python).

Example:

PHP - http://example.com/script.php

Python - http://example.com/script.py

P.S. I know about mod_rewrite and other similar tricks that can do that. But it is only a disguise, and not a direct run.

UPD: My .htaccess file. index.py works, but other python scripts get 404 error.

<Files *.py>
SetHandler wsgi-script
Options ExecCGI FollowSymLinks
</Files>
 DirectoryIndex index.py

That doesn't look as cool as having a wsgi app running, so I recommend that you use the flask framework which is as simple as can be a sane framework.

Here's a link describing the install procedure on mod_wsgi.

Later on, you might want to consider a cool framework like Django, Pyramid, Grok ...

If you really want to use mod_wsgi like mod_php check Graham Dumpleton's great answer.