如何从javascript或html运行python代码?
我用python编写了读取CSV文件的代码。现在,我想从javascript或HTML运行python代码 下面是python代码如何从javascript或html运行python代码?,javascript,python,html,css,Javascript,Python,Html,Css,我用python编写了读取CSV文件的代码。现在,我想从javascript或HTML运行python代码 下面是python代码 with open('C:\\Users\\Desktop\\Summer.csv') as csvDataFile: csvReader = csv.reader(csvDataFile) for row in csvReader: print(row) 下面是html和javascript代码 $.
with open('C:\\Users\\Desktop\\Summer.csv') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
print(row)
下面是html和javascript代码
$.ajax({
url: "C:\\Users\\Pictures\\test.py",
success: function(response) {
// here you do whatever you want with the response variable
}
});
}
在py文件中的函数中绑定此代码
$.ajax({
url: "..\test.py\somefunctionName",
success: function(response) {
// here you do whatever you want with the response variable
}
});
}
使用url paramater调用该函数,您就可以开始了您必须发送http请求,并且后端的处理程序必须是调用脚本的处理程序。客户端JS无法运行文件。它可以呈现其他JS,或者使用HTML做一些事情,但是它不能运行其他语言文件PHP是否运行python文件?FZ在这里,我将python代码放入函数中。导入csv def SomeFunctionName():打开('C:\\Users\\tmaga\\Desktop\\Summer.csv')作为csvDataFile:csvReader=csv.reader(csvDataFile)用于csvReader:print(row)SomeFunctionName()中的行您希望我在javascript的URL行代码中做什么?在URL端,使用URL的工作方式调用该函数。/test/SomeFunctionName这完全取决于您的URL在应用程序中的工作方式。尝试直接从浏览器地址栏调用该函数,无论它是什么URL,都可以工作。您能理解我的意思吗?I我知道你的意思,但我不知道该怎么做,因为我是javascript新手。
$.ajax({
url: "..\test.py\somefunctionName",
success: function(response) {
// here you do whatever you want with the response variable
}
});
}