POST后无法使用Flask render_template

时间:2016-02-26 21:29:52

标签: ajax flask

服务器收到Ajax POST后,我想渲染一个特定的模板,但模板没有渲染,没有错误,什么也没有。我认为这与接收POST有关。关于问题可能是什么想法?

使用Javascript:

function sendAjax(stringifiedData){
    var csrfToken = document.getElementById("csrf_token").getAttribute("content");
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/completed/');
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.send(stringifiedData);
}

Flask服务器:

@app.route('/completed/', methods=['POST'])
def completed():
    data = request.json['data']
    logger.debug("data:{0}".format(data)) #This logs OK
    return render_template('index.html')  #Doesn't render

0 个答案:

没有答案
相关问题