嗨,我在Google App引擎上使用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找到内容类型:
  text / html; charset = utf-8位置:
  http://localhost:8080/edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html
  内容长度:299
  
  
  重定向中...
  重定向中...您应该
  自动重定向到目标
  网址:/edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html。
  如果没有,请单击链接。


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

最佳答案

在Flask框架输出响应之前,代码中的某些内容会在响应中输出文本(看起来就像在打印“图像”一样)-很可能您的代码中有打印语句。结果,标头烧瓶尝试将输出解释为响应主体的一部分。

07-28 02:54
查看更多