title: How do I POST hidden FileFields in Django template?
body: <p>I'm attempting to deal with uploading files in Django and I've hit a snag.  My goal is to create a form which allows users to upload text and file data, preview that input, and then publish it. </p>
  
  <p>I put all the logic in a single view with multiple templates associated with the various submit buttons.  I didn't want to save all of the instances and then create a custom manager for published posts.  However, perhaps I should do that.</p>
  
  <p>My issue is that my file formset isn't working properly.  When I just submitted the data, without previewing it, it was fine.  But, once, I started POSTing back forth to different templates, it stopped working.  I know that you want to HttpResponseRedirect after a POST, but i figured my method was fine in this case.  I honestly have no clue. </p>
  
  <p>Here's my view logic</p>
  
  <pre><code>def post(request):
      page="post"
  #check if user has already posted and if so, direct them to their account post history page
  try:
      user=User.objects.get(pk=request.user.id)
  except User.DoesNotExist:   
      user=''
  if user:
      try:
          post=user.post_set.all()[0]
          return HttpResponseRedirect("/profile/post/")
  
      #Here a user who has not posted is shown a form to do so
      except IndexError:
          postform=PostForm(prefix="post")
          PhotoFormSet=modelformset_factory(Post_Photo,exclude=('post',), extra=4, max_num=4)
          photo_formset=PhotoFormSet(queryset=Post_Photo.objects.filter(post__lt=0),prefix="photos")  #lt 0 is a hack to return an empty query set, so that other photos aren't returned with the form
  
  #Here an anonymous user sees the form, though they can't successfully submit
  else:
      postform=PostForm(prefix="post")
      PhotoFormSet=modelformset_factory(Post_Photo,exclude=('post',), extra=4, max_num=4)
      photo_formset=PhotoFormSet(queryset=Post_Photo.objects.filter(post__lt=0),prefix="photos")
  
  
  if request.method=='POST' and user and request.POST.get('preview'):     
      photo_formset=PhotoFormSet(request.POST, request.FILES, prefix="photos")
      postform=PostForm(request.POST,prefix="post")
      if postform.is_valid() and photo_formset.is_valid():
          post=postform.save(commit=False)
          photos=photo_formset.save(commit=False)
          return render_to_response('website/preview_post.html', {'page':page,'post':post,'photos':photos,'photo_formset':photo_formset}, context_instance=RequestContext(request))
      else:
          return HttpResponse('error test')
  
  
  if request.method=='POST' and user and request.POST.get('edit'):
      photo_formset=PhotoFormSet(request.POST, request.FILES, prefix="photos")
      postform=PostForm(request.POST,prefix="post")
      neighborhood=request.POST.get('post-neighborhood','')
      if postform.is_valid() and photo_formset.is_valid():
          return render_to_response('website/post_upload.html', {'page':page, 'neighborhood':neighborhood,'postform':postform, 'photo_formset':photo_formset}, context_instance=RequestContext(request))
      else:
          return HttpResponse(postform.errors)
  
  
  if request.method=='POST' and user and request.POST.get('publish'):     
      photo_formset=PhotoFormSet(request.POST, request.FILES, prefix="photos")
      postform=PostForm(request.POST,prefix="post")
      if postform.is_valid() and photo_formset.is_valid():
          post=postform.save(commit=False)
          post.user=user
          post.save()
          photos=photo_formset.save(commit=False)
          for photo in photos:
              photo.post=post
              photo.save()
          return HttpResponse('/post_upload/?success=1')
      else:
          return HttpResponse('%s' %postform.errors)
  return render_to_response("website/post_upload.html", {'page':page,'postform':postform,'photo_formset':photo_formset}, context_instance=RequestContext(request))        
  </code></pre>
  
  <p>In my preview template, I include hidden inputs that are then POSTed either back to the edit page or published.  My photo_formset is contained in a div with display:none property so it's invisible.  </p>
  
  <p>When I POST from the edit page, the hidden text inputs go through but the FILE inputs do not.  What can I do about this?</p>
  
  <p>Thanks</p>