【问题标题】:Flask redirects on GAEGAE 上的 Flask 重定向
【发布时间】:2011-07-24 01:15:48
【问题描述】:

您好,我在 Google 应用引擎上使用 Flask (http://flask.pocoo.org/)。我有以下代码

@app.route("/edit.html", methods=['GET', 'POST'])
def create():
if request.method == 'GET':
    form = ImageForm()  
    return render_template('edit.html', title=u'Add', form=form)

if request.method == 'POST':
    image = Image()        
    form = ImageForm(request.form, image)
    if form.validate() and request.files['image']:
        form.populate_obj(image)
        if request.files['image']:
            image.file = request.files['image'].read()
        image.put()
        return redirect(url_for("edit", id=image.key()))
    else:
        return render_template('edit.html', title=u'Add', form=form)

@app.route("/edit/<id>.html", methods=['GET', 'POST'])
def edit(id):
    image = Image.get(id) 
    form  = ImageForm(request.form, image)
    return render_template('edit.html', title=u'Edit', form=form)   

但浏览器不会将我重定向到

中的给定网址
return redirect(url_for("edit", id=image.key()))

我收到一条消息:

图像状态:302 找到内容类型: 文本/html; charset=utf-8 位置: http://localhost:8080/edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html 内容长度:299

正在重定向...

重定向...

你应该 自动重定向到目标 网址:/edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html。 如果没有点击链接。

我不明白我的代码有什么问题?

【问题讨论】:

    标签: python google-app-engine redirect flask


    【解决方案1】:

    在 Flask 框架输出其响应之前,您的代码中的某些内容正在将文本输出到响应中(它看起来像是在打印“图像”)——很可能您的代码中某处有一个打印语句。结果,标头烧瓶尝试将输出解释为响应正文的一部分。

    【讨论】:

      猜你喜欢
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 2020-06-19
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 2013-02-13
      相关资源
      最近更新 更多