![](/img/trans.png)
[英]How can I send a XML from HTML in string to Python (using Flask) using Fetch API in Javascript
[英]How to send a HTML string from Javascript to Flask (python)?
我想将html脚本发送到python Flask路由。 它可以是html页面的内容(带有标签和文本内容)。
这是JavaScript部分:
var xhr = new XMLHttpRequest();
var url = "http://localhost:5000/todo/api/v1.0/process/" + htmlstring;
xhr.open('GET', url, false);
xhr.send();
var retrievedtext = xhr.responseText; //This will be returned by Flask
该代码的烧瓶部分为:
@app.route('/todo/api/v1.0/clean/<source_code>', methods=['GET'])
def process_html_code(source_code):
//do processing
return result
但是,在发送html时,我总是会收到404错误,因为这是不允许的。 有什么好的方法可以将html发送到flask?
您需要在Javascript代码中使用与在Python代码中定义的相同的路由。
在烧瓶应用中,您定义了一条路线
/todo/api/v1.0/clean/<source_code>
但是在您的Javascript代码中,您尝试向发送请求
http://localhost:5000/todo/api/v1.0/process/
那不合适。 根据定义的路径在Javascript代码中更改网址:
var url = "http://localhost:5000/todo/api/v1.0/clean/" + htmlstring;
这可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.