运行Python脚本像PHP [英] Running Python scripts like PHP

查看:216
本文介绍了运行Python脚本像PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有服务器上的Apache 2 + +的mod_wsgi的Python 2.6。

我想从Python中像PHP脚本运行脚本。这个想法可能看起来很傻,但我很习惯了(至少在第一次学习Python)的。

例如:

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

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

P.S。我知道mod_rewrite的和其他类似的技巧,可以做到这一点。但这仅仅是一种伪装,而不是直接运行。

UPD:我的.htaccess文件。 index.py作品,但其他的Python脚本获得404错误。

 <文件*的.py>
SetHandler WSGI脚本
选项​​ExecCGI了FollowSymLinks
< /文件>
 DirectoryIndex的index.py


解决方案

这看起来并不酷为具有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.

这篇关于运行Python脚本像PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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