开发者

Flask redirects on GAE

Hi I am using Flask (http://flask.pocoo.org/) on Google app engine. I have a following code

@app.route("/edit.html", methods=['GET', 'POST'])
def create():
if req开发者_JAVA技巧uest.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)   

but browser doesn't redirect me to an a given url in

return redirect(url_for("edit", id=image.key()))

I get a message:

image Status: 302 FOUND Content-Type: text/html; charset=utf-8 Location: http://localhost:8080/edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html Content-Length: 299

Redirecting...

Redirecting...

You should be redirected automatically to target URL: /edit/agtyb3VnaC1kcmFmdHILCxIFSW1hZ2UYDQw.html. If not click the link.

I can't understand what's fault with my code?


Something in your code is outputting text to the response before the Flask framework outputs its response (it looks like whatever it is is printing 'image') - most likely you have a print statement somewhere in your code. As a result, the headers flask tries to output get interpreted as part of the body of the response instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜