简体   繁体   English

python和django:从django网络表单执行python脚本?

[英]python and django: execute python script from django web form?

I have fully functional python program which I run from shell. 我有从外壳运行的功能齐全的python程序。 All arguments and options are supplied using option parser. 所有参数和选项均使用选项解析器提供。 What I would like to do is to create simple web interface for this program using django. 我想做的是使用django为该程序创建简单的Web界面。

I am stacked on transferring values received from web form to python script )) Actually how can I execute python script in this way? 我堆积了从Web表单接收到的值到python脚本的传输))实际上,我如何以这种方式执行python脚本?

Thanks in advance! 提前致谢!

If your python program has a bit that looks like this: 如果您的python程序看起来像这样:

import sys
if __name__ == "__main__":
  args = sys.argv 
  main(args)

Then just import it, and call it's main() method with your args in the same format as sys.argv. 然后,只需将其导入,并使用与sys.argv相同的格式将它的args调用为main()方法即可。 Sorted. 排序。 That would be the pythonic way of doing things. 那将是做事的Python方式。

Otherwise you need a general way of executing an external program from python - os.system and its friends. 否则,您需要一种从python-os.system及其朋友执行外部程序的通用方法。 This is covered elsewhere. 这在其他地方有介绍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM