V
V
Valery Semenov2012-09-19 13:22:45
Python
Valery Semenov, 2012-09-19 13:22:45

uploading files to defrom. How?

comprehend the pyramid. (and python with it)
I use the defrom module. Rather, I started using it and immediately ran into incomprehensibility. How to upload a file using defrom.

screwed the FileUploadWidget widget, but where to look for the file after submitting the form? Tell…

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gelas, 2012-09-19
@Ravall

Here is an example
http://deformdemo.repoze.org/file/

class Schema(colander.Schema):
    upload = colander.SchemaNode(
        deform.FileData(),
        widget=deform.widget.FileUploadWidget(tmpstore))

The fields of the FileData type contain all the necessary data
. Apparently, when processing the form, it is best to take a file (in form.upload.fp) and save it to disk where necessary.
Also pay attention to the tmpstore parameter of deform.widget.FileUploadWidget by
creating your own tmpstore you can control where the temporarily uploaded file will be stored

G
gelas, 2012-09-19
@gelas

you can save like this

controls = request.POST.items()
captured = form.validate(controls)
file_data = captured['upload']['fp']
    with open('/tmp/%s' % captured['upload']['filename'], 'wb') as new_file:
        new_file.write(file_data.read())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question