On Wed, May 15, 2013 at 9:47 AM, Tom Evans <tevans...@googlemail.com> wrote:
> On Wed, May 15, 2013 at 4:19 PM, Larry Martell <larry.mart...@gmail.com> 
> wrote:
>> On Wed, May 15, 2013 at 9:04 AM, Tom Evans <tevans...@googlemail.com> wrote:
>>> On Wed, May 15, 2013 at 3:38 PM, Larry Martell <larry.mart...@gmail.com> 
>>> wrote:
>>>> I have a form with an upload files button. The form is POSTed so that
>>>> I can get the file list in HttpRequest.FILES (which is only populated
>>>> for a POST). But I have other parameters I want to pass back as well
>>>> (which I cannot do in POST). So I changed it to a GET, but now the
>>>> list of files is a string, and not a list of file objects. Is there a
>>>> way I can get a list of file objects and other parameters sent back at
>>>> the same time?
>>>>
>>>
>>> Why can you not get the additional parameters in a POST request, this
>>> is unclear (and would be the normal way of handling this).
>>
>> Yes, it's unclear to me as well. ;-) The other parameters are not sent
>> back on POST. The URL doesn't have them and they are not in the
>> request.META['QUERY_STRING']. So I added onsubmit to my form that
>> calls a javascript function that puts the parameters in the URL and
>> that seems to automagically change it to a GET and HttpRequest.FILES
>> is no longer populated.
>>
>
> In a POST request the data is url encoded and sent as the request body
> - along with any file data. You don't need to do anything magic with
> JS to make this work.
>
> Can you show some HTML and python of how you are presenting and
> processing the form?

Here's the relavent HTML:

  <form id="upload" method="POST" enctype="multipart/form-data"
  action="/report/CDSEM/DR4iBeta/dr4iupload/">
  <div style='display:none'><input type='hidden'
name='csrfmiddlewaretoken' value='XXXXXXXXXXX' /></div>
  <div class="filter_group">
    <div class="filter">
         <label for="pixel_size">Pixel Size</label><br />
         <input style="float: left; width: 40px" type="text"
disabled="True" value="6" id="pixel_size" name="pixel_size">
    </div>
    <div class="filter">
         <label for="fov">FOV</label><br />
         <input style="width: 30px" type="text" disabled="True"
value="3" id="fov" name="fov">
    </div>
    <div class="filter">
         <label for="template_recipe">Template Recipe</label><br />
         <input style="width: 200px" type="text" disabled="True"
value="SF/SF/SF/SF_Template_Recipe" id="template_recipe"
name="template_recipe">
    </div>
    <div class="filter">
         <label for="template_target">Template Target</label><br />
         <input style="width: 200px" type="text" disabled="True"
value="SF/SF/SF/SF_IMAQ_Template_Target" id="template_target"
name="template_target">
    </div>
  </div>
  <div>
  <input type="file" name="klarf_files" id="klarf_files" multiple=""
style="display: inline; padding-top: 5px; padding-left: 2px; " />
  <input type="submit" class="submit" style="width: 70px; display:
inline;" value="Upload" />
  </form>

The select the files with the file button and upload them with the
Upload botton. My view gets called, but I have the files in
request.FILES but I don't get the other 4 input fields.

Here's the relavent part of the view:

class UploadForm(forms.Form):
    klarf_files = forms.FileField()
    pixel_size = forms.CharField()
    fov = forms.CharField()
    template_recipe = forms.CharField()
    template_target = forms.CharField()

def dr4iupload(self, request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            for file in request.FILES.getlist('klarf_files'):
                 .
                 .
                 .

I get the klarf_files, but I can't get the other 4 fields. The form
does not have the cleaned_data dictionary:

(Pdb) print form.cleaned_data()
*** AttributeError: 'UploadForm' object has no attribute 'cleaned_data'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to