Hello. I'm using Flask and wtforms. Also, more specifically - on app engine in this example, so I am also using the app engine wtforms extension. I am looking for an example of form processing that includes files also. I don't need the app engine part of that, just the form part. I want to do something like: form = forms.MyForm(request.form) but I really want to pass in request.files as well. However, the wtforms api does not support that. Mutating request.form directly is no good, it is an ImmutableMultiDict. I can go down that road if needed, but I'll have to dig into that api a bit. Before I do that I thought I would check to see if there is a common pattern or best practices for this. Thanks for your help in advance. -- Jay
Jay, It turns out the Flask-WTF extension sets formdata to a copy of the request.form in order to update formdata with request.files. Source code here: https://bitbucket.org/danjac/flask-wtf/src/5eac9fb9ff93/flaskext/wtf/__init__.py My guess is you might need to do the same. Jonathan. On Wed, Jul 6, 2011 at 2:37 PM, Jay Baker <jbaker.work@gmail.com> wrote: > Hello. I'm using Flask and wtforms. Also, more specifically - on app engine > in this example, so I am also using the app engine wtforms extension. > > I am looking for an example of form processing that includes files also. I > don't need the app engine part of that, just the form part. > > I want to do something like: > form = forms.MyForm(request.form) > > but I really want to pass in request.files as well. However, the wtforms > api does not support that. Mutating request.form directly is no good, it is > an ImmutableMultiDict. I can go down that road if needed, but I'll have to > dig into that api a bit. Before I do that I thought I would check to see if > there is a common pattern or best practices for this. > > Thanks for your help in advance. > > -- Jay >
Thanks guys. Jonathan, that was exactly what I was looking for. The solution for me is to combine request.form and request.files. Everything else works great from there. Adam, fortunately I was not having a problem with that aspect of things. See the following app engine python google groups discussion. Somewhat recent advancements in the blobstore api make it much much easier to deal with. https://groups.google.com/d/topic/google-appengine-python/jWK00RFM9o8/discussion Thanks again. On Wed, Jul 6, 2011 at 4:45 PM, Jonathan Zempel <jzempel@gmail.com> wrote: > Jay, > > It turns out the Flask-WTF extension sets formdata to a copy of the > request.form in order to update formdata with request.files. Source code > here: > https://bitbucket.org/danjac/flask-wtf/src/5eac9fb9ff93/flaskext/wtf/__init__.py > > My guess is you might need to do the same. > > Jonathan. > > > On Wed, Jul 6, 2011 at 2:37 PM, Jay Baker <jbaker.work@gmail.com> wrote: > >> Hello. I'm using Flask and wtforms. Also, more specifically - on app >> engine in this example, so I am also using the app engine wtforms extension. >> >> I am looking for an example of form processing that includes files also. I >> don't need the app engine part of that, just the form part. >> >> I want to do something like: >> form = forms.MyForm(request.form) >> >> but I really want to pass in request.files as well. However, the wtforms >> api does not support that. Mutating request.form directly is no good, it is >> an ImmutableMultiDict. I can go down that road if needed, but I'll have to >> dig into that api a bit. Before I do that I thought I would check to see if >> there is a common pattern or best practices for this. >> >> Thanks for your help in advance. >> >> -- Jay >> > >
Check the list archive. Its all changed a little with the new BlobStore API and I have not seen any example code using it. In the archive you will find a few samples of how people have handled it, for instance: http://flask.pocoo.org/mailinglist/archive/2011/4/10/flask-%2B-googleappengine-%2B-blobstore/ or http://flask.pocoo.org/mailinglist/archive/2011/1/8/app-engine-blobstore/ Essentially you don;t use WTForms for the upload, just a form that posts to a blobstore url and then you handle the redirect Of course someone may have coded an improved version using the new BlobStore API, in which case I'd like to see some sample code too. Thanks A On Jul 6, 2011, at 4:37 PM, Jay Baker wrote: > Hello. I'm using Flask and wtforms. Also, more specifically - on app > engine in this example, so I am also using the app engine wtforms > extension. > > I am looking for an example of form processing that includes files > also. I don't need the app engine part of that, just the form part. > > I want to do something like: > form = forms.MyForm(request.form) > > but I really want to pass in request.files as well. However, the > wtforms api does not support that. Mutating request.form directly is > no good, it is an ImmutableMultiDict. I can go down that road if > needed, but I'll have to dig into that api a bit. Before I do that I > thought I would check to see if there is a common pattern or best > practices for this. > > Thanks for your help in advance. > > -- Jay