烧瓶在GAE上重定向

1 python google-app-engine redirect flask

您好我在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)   
Run Code Online (Sandbox Code Playgroud)

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

return redirect(url_for("edit", id=image.key()))
Run Code Online (Sandbox Code Playgroud)

我收到一条消息:

image状态:302 FOUND Content-Type:text/html; charset = utf-8位置: http://localhost:8080/edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html 内容长度:299

重定向...

重定向...

您应该自动重定向到目标URL:/edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html.如果没有,请单击链接.

我无法理解我的代码有什么问题?

Nic*_*son 7

最有可能您的代码中有一个打印语句的地方 - 在瓶框架输出其响应(它看起来像不管它是正在打印"图像")之前的东西在你的代码输出文本的响应.结果,标题瓶尝试输出被解释为响应主体的一部分.