
js 调用 python 函数
在 python 中定义函数:
def a():
print('1')要让 js 能够调用 python 函数,需要将其暴露为 web api:
使用 flask 框架:
立即学习“Java免费学习笔记(深入)”;
from flask import flask
app = flask(__name__)
@app.route('/a')
def call_python_function():
a()
return 'success'
app.run()通过 js 调用 api:
fetch('/a')
.then(response => response.text())
.then(result => console.log(result));此时,js 可以通过发送 ajax 请求来调用 python 函数 a(),并显示返回的结果。










