title: Django - Pass a file to a session in form_valid
body: <p>I have the following code in <code>views.py</code>:</p>
  <pre><code>class UploadFile(CreateView):
      form_class = UploadFileForm
      template_name = &quot;tool/upload.html&quot;
      success_url = reverse_lazy('tool:edit_columns')
  
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          context['file'] = self.request.session['file']
          return context
  
      def form_valid(self, form):
          form.instance.name = form.instance.file.name
          row_number = form.instance.header_row
          file = form.instance.file
          df = pd.read_csv(file)
          names = list(df.columns)
          return super().form_valid(form)
  </code></pre>
  <p>And this code in <code>forms.py</code>:</p>
  <pre><code>class UploadFileForm(forms.ModelForm):
  
      class Meta:
              model = CheckFile
              fields = ['file', 'header_row', ]
  </code></pre>
  <p>I want to pass the <code>file</code> object and the columns <code>names</code> to the page <code>edit_columns.html</code>. I've been looking for infos and I think I have to use a session to pass the <code>file</code> object but with the code I tried, I have the following error:
  <code>KeyError: 'file'</code></p>
  <p>Could you please help me?</p>
  <p>Thanks!</p>