【发布时间】:2015-09-15 18:31:31
【问题描述】:
请帮我解决问题:Flask 不想在表单提交后重定向。 代码:
from flask import Flask, render_template, request, redirect, url_for
....
@app.route('/auth/')
def auth():
return render_template('auth.html')
这段代码运行良好:),auth.html 渲染表单:
{% extends "system.html" %}
{% block content %}
<form id="authen">
<input type="text" id="avtor_sku" pattern="[0-9]{1,13}" maxlength="13" value='' autofocus required>
</form>
{% endblock %}
提交此表单 - 通过 js 代码:
$(document).ready( function(){$('#authen').submit( function(){ var avtor_sku = $("#avtor_sku").val();
data1= '' + avtor_sku;
$.ajax({type: "GET", url: "/auth_echo/", contentType: "application/json; charset=utf-8",
data: {auth_echo_value: data1}, success: function() {alert(1)}});
return false;});});
此代码中的警报(1) - 工作。 路由/auth_echo/:
@app.route('/auth_echo/', methods=['GET'])
def auth_echo():
return redirect(url_for('openday'))
重定向不起作用。为什么?
【问题讨论】: