title: django problem uploading and saving documents
body: <p>I am working on a django app.  One part would involve uploading files (e.g. spreadsheet or whatever).  I am getting this error:</p>
  
  <pre><code>IOError at /fileupload/
  
  [Errno 13] Permission denied: 'fyi.xml'
  </code></pre>
  
  <p>Where 'fileupload' was the django app name and 'fyi.xml' was the test document I was uploading.</p>
  
  <p>So, I used chmod and chown to make the [project directory]/static/documents/ folder writable to apache.  Actually I even tried just making it chmod 777, still no luck.</p>
  
  <p>So, in my settings.py I just changed where my MEDIA_ROOT was:</p>
  
  <pre><code>MEDIA_ROOT = '/var/www/static/'
  </code></pre>
  
  <p>Then, in case it was an SELinux thing, I created the new documents directory in /var/www/static'...</p>
  
  <pre><code>drwxr-xr-x 2 apache root 4096 Aug 13 11:20 documents
  </code></pre>
  
  <p>Then I did these commands to try to change the context so apache would be allowed to write here.  I'm not too familiar with this distro, it's the flavor of Red Hat we're given, so I've never had to go beyond chmod and/or chown to fix a permissions problem.</p>
  
  <pre><code>sudo chcon -h system_u:object_r:httpd_sys_content_t /var/www/static
  sudo chcon -R -h root:object_r:httpd_sys_content_t /var/www/static
  sudo chcon -R -h root:object_r:httpd_sys_content_t /var/www/static/*
  </code></pre>
  
  <p>None of this made any difference.  To be honest, I'm not positive that I even have SELinux here but since normal unix permissions didn't seem to work I thought I'd try it.</p>
  
  <p>So, does anyone have an idea on what to look at next?  Not sure how much code I should post here, but in case it would be helpful here's what's in my views.py:</p>
  
  <pre><code>views.py
  from django.http import HttpResponseRedirect
  from django.shortcuts import render_to_response
  from forms import UploadFileForm
  from fyi.models import Materials
  
  def handle_uploaded_file(f):
      destination = open('fyi.xml', 'wb+')
      for chunk in f.chunks():
          destination.write(chunk)
      destination.close()
  
  
  def upload_file(request):
      if request.method == 'POST':
          form = UploadFileForm(request.POST, request.FILES)
          if form.is_valid():
              handle_uploaded_file(request.FILES['document'])
              form.save()
              template = 'upload_success.html'
      else:
          form = UploadFileForm()
          template = 'fileupload.html'
      return render_to_response( template, {'form': form})
  </code></pre>
  
  <p>...any help would be appreciated.</p>