Javascript 如何从html页面调用python命令?

Javascript 如何从html页面调用python命令?,javascript,jquery,python,html,Javascript,Jquery,Python,Html,我想从我的html页面调用python命令 代码是: <form class="form" action="" method="post" name="new-service" enctype=multipart/form-data> <div class="control-group"> <div class="controls"> <input id="Search" name="Sea

我想从我的html页面调用python命令

代码是:

<form class="form" action="" method="post" name="new-service" enctype=multipart/form-data>
      <div class="control-group">

          <div class="controls">
               <input id="Search" name="Search" type="text" placeholder="Search.. eg: moto g" class="form-control input-xlarge search-query center-display" required="">
   <!--  here i want to call python command  or function  -->

          </div>
     </div>

      </form>

这里是从输入框中获取的。

直接从UI中无法调用命令。这是后端特定的。但是,在处理表单的视图中,可以执行以下操作:

from django.core.management import call_command
call_command('your_command_name', args, kwargs)
检查此处的文档页面以供参考:
不能直接从UI调用命令。这是后端特定的。但是,在处理表单的视图中,可以执行以下操作:

from django.core.management import call_command
call_command('your_command_name', args, kwargs)
检查此处的文档页面以供参考:
不能直接从UI调用命令。这是后端特定的。但是,在处理表单的视图中,可以执行以下操作:

from django.core.management import call_command
call_command('your_command_name', args, kwargs)
检查此处的文档页面以供参考:
不能直接从UI调用命令。这是后端特定的。但是,在处理表单的视图中,可以执行以下操作:

from django.core.management import call_command
call_command('your_command_name', args, kwargs)
检查此处的文档页面以供参考:

使用jQuery向服务器上的python脚本发送请求,该请求将作为CGI/Fast CGI脚本或通过WSGI(Apache的mod_WSGI)或mod_python(Apache的mod_python)处理

Python脚本将使用查询字符串接收输入

客户端示例:

<html><head><title>TEST</title>
<script type="text/javascript" src="jquery.js"></script>
<script>

pyurl = "/cgi-bin/main.py"; // Just for example. It can be anything. Doesn't need to be Python at all
function callpy (argdict) {
    $.post(pyurl, argdict, function (data) {    
    // Here comes whatever you'll do with the Python's output.
    // For example:
    document.write(data);
    });
}
</script>
</head><body>
<!-- Now use it: -->
<a href="#" onclick='javascript:callpy({"s": "bow", "someother": "argument"});'>CLICK HERE FOR TEST!!!</a>
</body></html>
测试
pyurl=“/cgi-bin/main.py”;//举个例子。它可以是任何东西。根本不需要是Python
函数callpy(argdict){
$.post(pyurl,argdict,函数(数据){
//下面是您将对Python输出执行的任何操作。
//例如:
文件。写入(数据);
});
}
在服务器端(例如CGI):

#/usr/bin/env python
导入cgi,cgitb
cgib.enable()
打印“内容类型:文本/html\n”
i=cgi.FieldStorage()
如果我有钥匙:
如果我[“s”]。值=“bow”:打印“Yeeeey!!!!我得到了“bow”!!!
” 否则:打印“呜呜!我得到了”,I[“s”].value“,而不是“鞠躬”
” 否则:打印“参数不存在!” 打印“所有收到的参数:” 对于i.keys()中的x:打印x,“

使用jQuery向服务器上的python脚本发送请求,该请求将作为CGI/Fast CGI脚本或通过WSGI(mod_WSGI用于Apache)或mod_python(也用于Apache)处理

Python脚本将使用查询字符串接收输入

客户端示例:

<html><head><title>TEST</title>
<script type="text/javascript" src="jquery.js"></script>
<script>

pyurl = "/cgi-bin/main.py"; // Just for example. It can be anything. Doesn't need to be Python at all
function callpy (argdict) {
    $.post(pyurl, argdict, function (data) {    
    // Here comes whatever you'll do with the Python's output.
    // For example:
    document.write(data);
    });
}
</script>
</head><body>
<!-- Now use it: -->
<a href="#" onclick='javascript:callpy({"s": "bow", "someother": "argument"});'>CLICK HERE FOR TEST!!!</a>
</body></html>
测试
pyurl=“/cgi-bin/main.py”;//举个例子。它可以是任何东西。根本不需要是Python
函数callpy(argdict){
$.post(pyurl,argdict,函数(数据){
//下面是您将对Python输出执行的任何操作。
//例如:
文件。写入(数据);
});
}
在服务器端(例如CGI):

#/usr/bin/env python
导入cgi,cgitb
cgib.enable()
打印“内容类型:文本/html\n”
i=cgi.FieldStorage()
如果我有钥匙:
如果我[“s”]。值=“bow”:打印“Yeeeey!!!!我得到了“bow”!!!
” 否则:打印“呜呜!我得到了”,I[“s”].value“,而不是“鞠躬”
” 否则:打印“参数不存在!” 打印“所有收到的参数:” 对于i.keys()中的x:打印x,“

使用jQuery向服务器上的python脚本发送请求,该请求将作为CGI/Fast CGI脚本或通过WSGI(mod_WSGI用于Apache)或mod_python(也用于Apache)处理

Python脚本将使用查询字符串接收输入

客户端示例:

<html><head><title>TEST</title>
<script type="text/javascript" src="jquery.js"></script>
<script>

pyurl = "/cgi-bin/main.py"; // Just for example. It can be anything. Doesn't need to be Python at all
function callpy (argdict) {
    $.post(pyurl, argdict, function (data) {    
    // Here comes whatever you'll do with the Python's output.
    // For example:
    document.write(data);
    });
}
</script>
</head><body>
<!-- Now use it: -->
<a href="#" onclick='javascript:callpy({"s": "bow", "someother": "argument"});'>CLICK HERE FOR TEST!!!</a>
</body></html>
测试
pyurl=“/cgi-bin/main.py”;//举个例子。它可以是任何东西。根本不需要是Python
函数callpy(argdict){
$.post(pyurl,argdict,函数(数据){
//下面是您将对Python输出执行的任何操作。
//例如:
文件。写入(数据);
});
}
在服务器端(例如CGI):

#/usr/bin/env python
导入cgi,cgitb
cgib.enable()
打印“内容类型:文本/html\n”
i=cgi.FieldStorage()
如果我有钥匙:
如果我[“s”]。值=“bow”:打印“Yeeeey!!!!我得到了“bow”!!!
” 否则:打印“呜呜!我得到了”,I[“s”].value“,而不是“鞠躬”
” 否则:打印“参数不存在!” 打印“所有收到的参数:” 对于i.keys()中的x:打印x,“

使用jQuery向服务器上的python脚本发送请求,该请求将作为CGI/Fast CGI脚本或通过WSGI(mod_WSGI用于Apache)或mod_python(也用于Apache)处理

Python脚本将使用查询字符串接收输入

客户端示例:

<html><head><title>TEST</title>
<script type="text/javascript" src="jquery.js"></script>
<script>

pyurl = "/cgi-bin/main.py"; // Just for example. It can be anything. Doesn't need to be Python at all
function callpy (argdict) {
    $.post(pyurl, argdict, function (data) {    
    // Here comes whatever you'll do with the Python's output.
    // For example:
    document.write(data);
    });
}
</script>
</head><body>
<!-- Now use it: -->
<a href="#" onclick='javascript:callpy({"s": "bow", "someother": "argument"});'>CLICK HERE FOR TEST!!!</a>
</body></html>
测试
pyurl=“/cgi-bin/main.py”;//举个例子。它可以是任何东西。根本不需要是Python
函数callpy(argdict){
$.post(pyurl,argdict,函数(数据){
//下面是您将对Python输出执行的任何操作。
//例如:
文件。写入(数据);
});
}
在服务器端(例如CGI):

#/usr/bin/env python
导入cgi,cgitb
cgib.enable()
打印“内容类型:文本/html\n”
i=cgi.FieldStorage()
如果我有钥匙:
如果我[“s”]。值=“bow”:打印“Yeeeey!!!!我得到了“bow”!!!
” 否则:打印“呜呜!我得到了”,I[“s”].value“,而不是“鞠躬”
” 否则:打印“参数不存在!” 打印“所有收到的参数:” 对于i.keys()中的x:打印x,“

我认为客户端(即浏览器)是不可能的,但服务器端是可能的。。这就是django、flask等的用途(即根据来自网页的参数执行python代码)。您需要使用web服务器来处理来自网页的传入请求。我认为这不可能是客户端(即浏览器),而是服务器端。。这就是django、flask等的用途(即根据来自网页的参数执行python代码)。您需要使用web服务器来处理来自网页的传入请求。我认为这不可能是客户端(即浏览器),而是服务器端。。这就是django、flask等的用途(即根据来自网页的参数执行python代码)。您需要使用web服务器来处理来自网页的传入请求。我认为客户端(即bro)是不可能的