Django FileField not including uploaded file in form output request
<p>I am having trouble getting access to a simple uploaded file which I need to parse without saving it. Since the file does not need to be saved I have not made a model for it. All other threads on this state the html form encoding type, name tag are the primary reasons why request.FILES is not appearing-- I have addressed these and still there is no request.FILES being captured.</p>

<p><strong>forms.py</strong></p>

<pre><code>class DataExportForm(forms.Form):
    docfile = forms.FileField(label='Select a template',help_text='Extracted info will be returned') 
</code></pre>

<p><strong>HTML</strong></p>

<pre><code>&lt;html&gt;
&lt;body&gt;
&lt;form action="." method="post" enctype="multipart/form-data"&gt;{% csrf_token %}

&lt;tr&gt;&lt;th&gt;&lt;label for="id_docfile"&gt;Select a template:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id
_docfile" name="docfile" type="file" /&gt;
&lt;button type="submit" name="action"&gt;Upload&lt;/button&gt;
&lt;br /&gt;&lt;span class="helptext"&gt;Zip file wil
l be returned with data&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;   
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt; 
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>if request.method=='POST':        
    form=DataExportForm(request.POST, request.FILES)
    if form.is_valid():
        #Code runs OK till here but request.FILES does not exist. 
        groupList=extractTemplateNames(request.FILES['file'].read())
</code></pre>

<p>I guess if I get it working I may find the file not in request.FILES['file'] but in request.FILES['docfile'] but at this point request.FILES does not exist. Any tips to solve this would be appreciated.</p>

<p>Most likely, problem is just that you are trying to access file using wrong name. Field on form has name  <code>docfile</code>. Same name it will have in <code>request.FILES</code> array. </p>

<p>Possibly, you simply misunderstood an error message saying that there is no <code>file</code> in <code>FILES</code>. </p>

<p>And <code>form.is_valid</code> access FILES array correctly, that is why form is considered to be valid. </p>

python html django filefield