
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(),并显示返回的结果。
以上就是如何使用 JavaScript 调用 Python 函数?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号