是否可以在 WordPress 网站上运行 Python 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30405549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to run a Python app on a WordPress site?
提问by
I have an idea for a web app and plan to learn Python as I go (right now I know html/css, some javascript, some php and sql). The app would be able to manipulate and analyze audio files, among other things.
我有一个关于 Web 应用程序的想法,并计划边走边学 Python(现在我知道 html/css、一些 javascript、一些 php 和 sql)。该应用程序将能够操作和分析音频文件等。
Ideally, I'd like to make the app available through my wordpress site so that I can take advantage of WordPress's login management and the plugin s2member's subscription management and content restriction capabilities.
理想情况下,我希望通过我的 wordpress 站点提供该应用程序,以便我可以利用 WordPress 的登录管理和插件 s2member 的订阅管理和内容限制功能。
Is that possible? Would it even make sense?
那可能吗?它甚至有意义吗?
If not, is there a better alternative to automate all of that (the subscription management, logins, payment processing, content restriction, etc) without having to code it myself?
如果没有,是否有更好的替代方法来自动化所有这些(订阅管理、登录、支付处理、内容限制等),而无需自己编写代码?
采纳答案by lecodesportif
I suggest you develop a REST API in Python and extend your Wordpress site to consume that API.
我建议您用 Python 开发 REST API 并扩展您的 Wordpress 站点以使用该 API。
For the Python side, you could go with Flask and use Flask-RESTful.
对于 Python 方面,您可以使用 Flask 并使用Flask-RESTful。
For the Wordpress side, have a look at this question.
对于 Wordpress 方面,看看这个问题。
回答by Cody Reichert
Sure, if you meet a couple of conditions:
当然,如果你满足几个条件:
- The server your wordpress site is on also has python
- And you have the ability run arbitrary python scripts on said server.
- 你的 wordpress 站点所在的服务器也有 python
- 并且您可以在所述服务器上运行任意 Python 脚本。
Here's a (very contrived) example of how to do it from a plugin:
这是一个(非常人为的)示例,说明如何从插件执行此操作:
call-python.php (plugin file):
call-python.php(插件文件):
<php
/*
Plugin name: Call Python
Author:..
....
*/
$pyScript = "/path/to/app.py";
exec("/usr/bin/python $pyScript", $output);
var_dump($output);
And the python script app.py:
以及 python 脚本 app.py:
print("Hello, World")
And that's it! That will dump Hello, world to the body. Obviously you'll need a bit more for a more complicated python app, but it will work.
就是这样!这会将 Hello, world 转储到 body。显然,对于更复杂的 python 应用程序,您需要更多,但它会起作用。
Like others are saying, there may be better "more correct" ways of doing it. But if your end goal is to run a python app from WordPress it's possible.
就像其他人所说的那样,可能有更好的“更正确”的方法来做到这一点。但是,如果您的最终目标是从 WordPress 运行 Python 应用程序,那是可能的。