假设我有这个设置
为什么点击“arrToPython”按钮后烧瓶不会将我重定向到“query_result.html”?更重要的是,我怎样才能做到这一点?
我尝试创建单独的路线,并使用烧瓶的“重定向”方法,但它也不适用于我:( test.py:
from flask import Flask
from flask import request, url_for
from flask import render_template
from flask import redirect, Response
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
def savingImage():
if request.method == 'GET':
return render_template('test.html')
if request.method == 'POST':
return render_template('query_result.html')
if __name__ == '__main__':
app.debug = True
app.run()
test.html
<!DOCTYPE html> <html> <head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> </head> <body>
<input id="arrToPython" type=button value="arrToPython" href="result" onclick = "arrToPython()">
<script type="text/javascript">
function arrToPython(){
var arr = ['one', 'two']
$.ajax({
type: 'POST',
url: 'http://localhost:5000/',
data: JSON.stringify(arr),
}).done(function(){
console.log('sent');
})
}
</script> </body> </html>
query_result.html
<br> Hola amigo!</br>