运行像 PHP 这样的 Python 脚本 [英] Running Python scripts like PHP
问题描述
服务器上有 Apache 2 + mod_wsgi + Python 2.6.
There are Apache 2 + mod_wsgi + Python 2.6 on server.
我想从 Python 运行脚本,如 PHP 脚本.这个想法可能看起来很愚蠢,但我已经习惯了(至少在第一次学习 Python 时).
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).
示例:
PHP - http://example.com/script.php
Python - http://example.com/script.py
附言我知道 mod_rewrite 和其他类似的技巧可以做到这一点.但这只是伪装,并不是直接跑.
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:我的 .htaccess 文件.index.py 有效,但其他 python 脚本出现 404 错误.
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
推荐答案
这看起来不像运行 wsgi 应用那么酷,所以我建议你使用 flask 框架,这是一个简单的框架.
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.
这是一个链接,描述了 在 mod_wsgi 上的安装过程.
Here's a link describing the install procedure on mod_wsgi.
稍后,您可能想考虑一个很酷的框架,例如 Django、Pyramid、Grok ...
Later on, you might want to consider a cool framework like Django, Pyramid, Grok ...
如果你真的想像 mod_php 一样使用 mod_wsgi,请查看 Graham Dumpleton 的好答案.
If you really want to use mod_wsgi like mod_php check Graham Dumpleton's great answer.
这篇关于运行像 PHP 这样的 Python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!