如何在Django中从HTML标记按钮在后台触发Python脚本? [英] How can i trigger a Python script in background from HTML tag button, in Django?

查看:384
本文介绍了如何在Django中从HTML标记按钮在后台触发Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请,我如何从Django平台运行python脚本?
我有一个自定义html页面,并且我有一个按钮标签(< button>< / button> ),我想从中触发python代码我已经在PDF的(出色的解析器)上写过文章。

Please, how can i run a python script from my Django platform? I have a custom html page and i have a button tag (<button></button>) from which i would like to trigger the python code I've written on PDF's (wonderful parser).

实际上,如果该应用程序的用户单击此 parse it (解析)按钮,它将触发我的python脚本存储在我的静态文件夹中,并打印回下表中提取的文本和图像:

Actually, if the user of this app clicks on this parse it button, it triggers my python script stored in my static folder, and prints back the extracted texts and images in the table below:

我非常需要您的帮助和可能的想法。

I greatly need your helps and possible ideas.

谢谢!

推荐答案

只需将脚本添加到视图并按如下方式调用它即可。即在 views.py 文件

Just add the script to a view and call it like this. i.e in the views.py file

< a href = {%url' wonderful_script'%} class = btn btn-primary role = button>精彩的解析器< / a>

请确保您也将该视图绑定到urls.py中的URL。

Make sure you bind that view to an url in urls.py too.

url(r'^ parse / $',wonderful_script,name ='wonderful_script')

这里的 wonderful_script 中间是您在views.py中定义的视图。它必须具有解析器脚本的所有代码。

Here the wonderful_script in the middle is the view that you defined in the views.py. It must have all the code of your parser script.

这篇关于如何在Django中从HTML标记按钮在后台触发Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆