title: django uploading files without model
body: <p>I would like to upload files (text/images) without a model  ( just using views and templates). I would ideally like to read or write to location.</p>
  
  <p>My current code is as below:</p>
  
  <p>In my template /foo/help/UploadFileContent.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;link rel="stylesheet" href="{{STATIC_URL}}/stylesheets/jquery-ui.css"&gt;
  &lt;div class="main-content"&gt;
      &lt;div class="container"&gt;
  
  
          &lt;div class="container"&gt;
              &lt;div class="row"&gt;
  
                  &lt;div class="box"&gt;
                      &lt;div class="box-content"&gt;
                          &lt;div class="col-md-12"&gt;
                              &lt;form method="post" id="fileupload" action="/helpsubmitfilecontent/" accept-charset="utf-8" class="fill-up"&gt;
                                  {% csrf_token %}
                                  &lt;div class="row"&gt;
                                      &lt;div class="col-lg-4"&gt;
  
                                          &lt;ul class="padded separate-sections"&gt;
                                              &lt;li&gt;
                                                  &lt;input type="text" name="name" id="name" placeholder="Name"/&gt;
                                              &lt;/li&gt;
  
                                              &lt;li&gt;
                                                  &lt;textarea name="content" id="content"
                                                            placeholder="Help Contents" style="height: 250px;width: 700px"&gt;&lt;/textarea&gt;
                                              &lt;/li&gt;
                                             &lt;li&gt;
                                                  &lt;input type="file" name="myfile" id="myfile" /&gt;
  
                                             &lt;/li&gt;
                                          &lt;/ul&gt;
  
                                          &lt;div class="form-actions"&gt;
                                              &lt;button type="submit" class="btn btn-blue"&gt;Submit&lt;/button&gt;
                                          &lt;/div&gt;
  
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/form&gt;
  
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;script&gt;
      $('#fileupload').submit(function(evnt){
         if($('#name').val().length &lt;=0){
             $('#name').attr('style','border-color:red');
             evnt.preventDefault();
         }
         if($('#content').val().length &lt;=0){
             $('#content').attr('style','border-color:red');
             evnt.preventDefault();
         }
      });
  
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In my help views:</p>
  
  <pre><code>def fileupload(request):
  
      return responsewrapper('pages/foo/help/UploadFileContent.html', locals(),request)
  
  def submitfilecontent(request):
      myhash = dict()
      myhash['name'] = request.POST['name'] # works
      myhash['filedata'] = request.POST['content'] # works
      handle_uploaded_file(request.FILES['myfile']) # error throws up here.
      return HttpResponseRedirect("/successupload")
  
  def handle_uploaded_file(f):
      destination = open('/home/foo/name.txt', 'wb+')
      for chunk in f.chunks():
          destination.write(chunk)
      destination.close()
  </code></pre>
  
  <p>The following error throws up while operating on the file data.</p>
  
  <pre><code>Exception Value:    
  "Key 'myfile' not found in &lt;MultiValueDict: {}&gt;"
  </code></pre>
  
  <p>Please advice. I would ideally not like to use any databases, as all i want is to import text/images to static location.</p>