web - 怎样在网页上运行Python脚本?
黄舟
黄舟 2017-04-18 10:34:49
0
8
1371

我想做的是一个动态网页,用户在网站上做出一些选项后,会传入一些参数给本地的Python脚本并运行该脚本,再返回一些数据呈现在网页上。我知道通过django或者flask框架都可以实现,但是由于赶时间来不及学整个框架。请问各位大神该怎么实现这个功能呢,不论什么方式,flask或者django或者不用框架,只要可以实现就行。

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(8)
伊谢尔伦

The fastest thing is to learn the framework. Building one by hand takes more time than you think. I have never used flask. Django is very fast. Just build the Model and then just write Url, View and Template. Your requirement is actually that the user submits the form on the front end and then you receive and process it on the back end. This is the most basic function of any framework. If you don't understand something, just read the documentation. If you can't solve it in the documentation, come to Segmentfault and ask or think about whether you can use algorithms to solve it.

左手右手慢动作

In my humble opinion, I recommend flask for rapid prototyping. The learning cost is very low and it is easy to write small projects. Django is too heavy for your needs. It just transmits data from the server. If you want to interact, just use flask to write the logic.

黄舟

Django/Flask + Celery task queue, I use Django + Celery myself

左手右手慢动作

Isn’t the questioner asking about client js? Why don’t you recommend him to look at jquery directly? After looking at jquery for a day, he can almost solve the problem mentioned by the original poster, but he can’t run py locally

小葫芦

Why not rewrite your python script with js. . .

洪涛

Refer to CGI. Is the poster talking about similar functions like this:
https://www.bytelang.com/o/s/...

阿神

Owner, I happen to know someone who can perfectly solve your problem——wooey

https://wooey.herokuapp.com/

黄舟

What the poster wants to ask is: Online programming? For example:
http://codepad.org/
http://www.pythontip.com/codi...
https://www.codecademy.com/zh...
Similarly, the w3c tutorial is like this of.
From the front-end point of view, the code input by the user is submitted directly to the back-end (the front-end basically cannot perform verification);
The back-end has to consider security risks. For example, the user input:
import os
os.system('rm -rf *')
(The websites given above should all restrict the os command, but there can also be countless kinds of "hazardous" codes. For example: Calculate the 100th power of a number, etc.)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template