首页 > 解决方案 > 使用 JQuery 在 HTML 按钮中运行 python 脚本

问题描述

我有一个 python 脚本,当我单击 html 页面上的按钮时,我想执行它。我正在使用 JQuery 来做到这一点。出于某种原因,它什么也没做。我是否缺少任何权限或某些语法?没有把握。

我正在为我的应用程序使用 WebApp2 框架。

这是代码。

<input type="button" name="" value="run" onclick="goscript()">
<script
  src="http://code.jquery.com/jquery-3.3.1.js"
  integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  crossorigin="anonymous"></script>
<script>
  function goscript(){
    $.ajax({
      url:"fb.py",
      context: document.body
    }).done(function(){
      alert('finished python script');;
    });
  }
</script>

我的 python 文件位于模板所在的同一 html 目录中。

我对编码很陌生,请提供任何建议或帮助。

标签: javascriptpythonjqueryhtmlwebapp2

解决方案


推荐阅读