问题描述
我有我想要一个Python脚本,从浏览器中运行,它似乎是的mod_wsgi的路要走,但该方法感觉太重量级,将需要修改脚本的输出。我想我想一个PHP的方法最好。这些脚本不带任何输入,将只在内部网络上进行访问。
I have a Python script that I'd like to be run from the browser, it seem mod_wsgi is the way to go but the method feels too heavy-weight and would require modifications to the script for the output. I guess I'd like a php approach ideally. The scripts doesn't take any input and will only be accessible on an internal network.
我在Linux上运行的Apache与已经设立的mod_wsgi,有什么选择这里?
I'm running apache on Linux with mod_wsgi already set up, what are the options here?
推荐答案
我会去微框架方法,以防万一你的要求改变 - 你永远不知道,它可能最终被一个应用程序,而只是一个基本的转储。 ..也许最简单的(和老式的方式!?)是使用CGI:
I would go the micro-framework approach just in case your requirements change - and you never know, it may end up being an app rather just a basic dump... Perhaps the simplest (and old fashioned way!?) is using CGI:
- 复制你的脚本,包括
打印的Content-Type:text / plain的\\ n'
其他任何输出前为sys.stderr
- 把这个脚本Apache2的地方都可以访问它(你的cgi-bin举例)
- 确保脚本是可执行的
- 确保
的.py
添加到Apache的CGI处理程序
- Duplicate your script and include
print 'Content-Type: text/plain\n'
before any other output tosys.stdout
- Put that script somewhere apache2 can access it (your cgi-bin for instance)
- Make sure the script is executable
- Make sure
.py
is added to the Apache CGI handler
可是 - 我不认为反正这将是一个梦幻般的优势(从长远来看,至少)
But - I don't see anyway this is going to be a fantastic advantage (in the long run at least)
这篇关于Web服务器服务于Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!