Home  >  Q&A  >  body text

web - 怎样在网页上运行Python脚本?

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

黄舟黄舟2741 days ago1326

reply all(8)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:36:49

    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.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:36:49

    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.

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:36:49

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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:36:49

    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

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:36:49

    Why not rewrite your python script with js. . .

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:36:49

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

    reply
    0
  • 阿神

    阿神2017-04-18 10:36:49

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

    https://wooey.herokuapp.com/

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:36:49

    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.)

    reply
    0
  • Cancelreply