title: django-import-export import data from views.py
body: <p>I'm working on django-import-export library for importing &amp; exporting xls format, Everything working probably at AdminModel,Now I'm trying to make importing working with views.py &amp; templates but for some reasons didn't work with me </p>
  
  <p>views.py</p>
  
  <pre><code>def simple_upload(request):
  if request.method == 'POST':
      person_resource = resources.SimsResource()
      dataset = Dataset()
      new_persons = request.FILES['myfile']
  
      imported_data = dataset.load(new_persons.read())
      result = person_resource.import_data(dataset, dry_run=True)  # Test the data import
  
      if not result.has_errors():
          person_resource.import_data(dataset, dry_run=False)  # Actually import now
  
      return render(request, 'import_sims.html', {'errors': result.has_errors(), 'result': result})
  
  return render(request, 'import_sims.html')
  </code></pre>
  
  <p>resources.py</p>
  
  <pre><code>class SimsResource(resources.ModelResource):
  class Meta:
      model = models.Sim
      fields = ['s_serial_number', 's_number', 's_provider', 'status']
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class UploadFileForm(forms.Form):
      file = forms.FileField()
  </code></pre>
  
  <p>url.py </p>
  
  <pre><code>    url(r'^importing_sims/$', views.simple_upload, name='Import'),
  </code></pre>
  
  <p>template </p>
  
  <pre><code>    {% if errors %}
          errors:
          {{ errors }}
          &lt;br&gt;&lt;br&gt;&lt;br&gt;
          resluts :
          {{ result }}
      {% endif %}
  
        &lt;form method="post" enctype="multipart/form-data"&gt;
          {% csrf_token %}
          &lt;input type="file" name="myfile"&gt;
          &lt;button type="submit"&gt;Upload&lt;/button&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p>and error output : </p>
  
  <pre><code>errors: True 
  resluts : &lt;import_export.results.Result object at 0x1072b75f8&gt;
  </code></pre>
  
  <p>UPDATE : </p>
  
  <p>after some updates in views.py here is the new error : </p>
  
  <pre><code>KeyError at /importing_sims/
  'id'
  </code></pre>
  
  <p>which is not showing in admin import </p>
  
  <p>and here is update : </p>
  
  <pre><code>def simple_upload(request):
      if request.method == 'POST':
      form = forms.UploadFileForm(request.POST, request.FILES)
      if form.is_valid():
          file = form.cleaned_data['file']
          data = bytes()
          for chunk in file.chunks():
              data += chunk
          dataset = XLS().create_dataset(data)
          result = resources.SimsResource().import_data(dataset, dry_run=False, raise_errors=True, user=request.user)
          return render(request, 'import_sims.html', {'errors': result.has_errors(), 'result': result})
  
  return render(request, 'import_sims.html')
  </code></pre>