如何从javascript或html运行python代码?

时间:2019-05-15 04:49:46

标签: 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代码

        $.ajax({
        url: "C:\\Users\\Pictures\\test.py",
        success: function(response) {
            // here you do whatever you want with the response variable
        }
        });

    }

1 个答案:

答案 0 :(得分:0)

with open('C:\\Users\\Desktop\\Summer.csv') as csvDataFile:
        csvReader = csv.reader(csvDataFile)
         for row in csvReader:
           print(row)     

将此代码绑定到py文件中的函数中

 $.ajax({
        url: "..\test.py\somefunctionName",
        success: function(response) {
            // here you do whatever you want with the response variable
        }
        });

    }

使用url参数调用该函数,您就很好了