title: FileField() does not show up in template
body: <p>I'm adding the file upload functionality to a website built by my predecessor. The current revision looks like the following: </p>
  
  <p><a href="https://i.stack.imgur.com/C70MV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C70MV.png" alt="enter image description here"></a></p>
  
  <p>The issue is that there should have been a button between <strong>Upload Custom Data</strong> and <strong>Upload</strong> for browsing and picking files, but there isn't.</p>
  
  <p>The weirder part is that, after choosing <strong>Asset 1</strong> and <strong>Asset 2</strong> and then clicking <strong>Calculate</strong>, the button for browsing files suddenly appears, and the <strong>Browse...</strong> and <strong>Upload</strong> buttons work fine: </p>
  
  <p><a href="https://i.stack.imgur.com/cW5a1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cW5a1.png" alt="enter image description here"></a></p>
  
  <p>The HTML code of this page is <strong>correlation.html</strong>:</p>
  
  <pre><code>{% extends "instvol/layout.html" %}
  {% block body %}
  
  
  
  &lt;div class="container about-container"&gt;
      &lt;div class="row"&gt;
          &lt;h2&gt;Correlation Analysis&lt;/h2&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
  
          &lt;form method="GET"&gt;
  
              &lt;div class="corr-form"&gt;
  
                  &lt;fieldset id="additional-field-model"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;div class="col-md-6 col-sm-12"&gt;
                              &lt;label class="col-md-12 control-label" for="field-a"&gt;Asset 1&lt;/label&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;select id="field-a" name="field-a"   class="form-control input-md"  required=""&gt;
                                      &lt;option disabled="" selected=""&gt;Select&lt;/option&gt;
                                      {% for ticker in ticker_list %}
                                          &lt;option value="{{ticker}}" {% if symbolName == ticker %}{% endif %}&gt;{{ticker}}&lt;/option&gt;
                                      {% endfor %}
                                  &lt;/select&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-md-2 col-xs-5"&gt;
                              &lt;label class="col-md-12 control-label" for="field-b"&gt;Asset 2&lt;/label&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;select id="field-b" name="field-b"   class="form-control input-md"  required=""&gt;
                                      &lt;option disabled="" selected=""&gt;Select&lt;/option&gt;
                                      {% for ticker in ticker_list %}
                                          &lt;option value="{{ticker}}" {% if symbolName == ticker %}{% endif %}&gt;{{ticker}}&lt;/option&gt;
                                      {% endfor %}
                                  &lt;/select&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-md-4 col-xs-7 text-right"&gt;
                              &lt;label class="col-xs-12 control-label" for="field-c"&gt;&lt;br/&gt;&lt;/label&gt;
                              &lt;a href="javascript:void(0);" class="btn btn-warning remove-this-field"&gt; &lt;span class="hidden-xs"&gt; Delete &lt;/span&gt; &lt;/a&gt; 
                              &lt;a href="javascript:void(0);" class="btn btn-success create-new-field"&gt; &lt;span class="hidden-xs"&gt; Add &lt;/span&gt; &lt;/a&gt; 
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/fieldset&gt;
              &lt;/div&gt;
  
  
              &lt;script&gt;
                  $('#additional-field-model').duplicateElement({"class_remove": ".remove-this-field",
                                                                 "class_create": ".create-new-field", });
              &lt;/script&gt;
  
              &lt;hr&gt;
  
              &lt;div class="form-group"&gt;
                      &lt;span class="glyphicon glyphicon-calendar" aria-hidden="true"&gt;&lt;/span&gt;
                      &lt;label for="input-daterange"&gt;Date Range&lt;/label&gt;
                      &lt;input type="text" class="form-control" name="daterange"/&gt;
              &lt;/div&gt;
              &lt;div&gt;
                      &lt;button type="submit" class="btn btn-primary"&gt;Calculate&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
      &lt;hr&gt;
  
      &lt;div class="row"&gt;
          &lt;div class="panel-body"&gt;
              &lt;!-- Standar Form --&gt;
              &lt;h4&gt;Upload Custom Data&lt;/h4&gt;
              &lt;form method="POST" enctype="multipart/form-data""&gt;
                  {% csrf_token %}
                  &lt;div&gt;
                      &lt;div class="form-group"&gt;
                  {{ form }}
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;button type="submit" class="btn btn-primary"&gt;Upload&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;hr&gt;
  
      &lt;div class="row"&gt;
  
          &lt;h4&gt; Asset Price&lt;/h4&gt;
          &lt;div class="col-lg" id="plotly-figure-his"&gt;
              {{ plot_div_spot|safe }}
          &lt;/div&gt;
          &lt;hr&gt;
          &lt;h4&gt;Historical Correlation&lt;/h4&gt;
          &lt;div class="col-lg" id="plotly-figure-his"&gt;
              {{ plot_div_his|safe }}
          &lt;/div&gt;
          &lt;hr&gt;
          &lt;h4&gt;Instantaneous Correlation&lt;/h4&gt;
          &lt;div class="col-lg" id="plotly-figure"&gt;
              {{ plot_div_inst|safe }}
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  &lt;/script&gt;
  
  {% endblock %}
  </code></pre>
  
  <p>The relevant part in <strong>views.py</strong> is as follows:</p>
  
  <pre><code>def correlation(request):
      if request.method == 'POST': #custom upload
          form = UploadFileForm(request.POST, request.FILES)
          if form.is_valid():
              cusdata = pd.read_csv(request.FILES['file'], header=None)
  
          spot1 = ['Asset 1', ]
          spot2 = ['Asset 2', ]
          symbolPair = list(zip(spot1, spot2))
  
          start = 1 
          end = len(cusdata)
  
          rhodata = []
          for pair in symbolPair:
              f1 = pd.DataFrame({'price':cusdata.iloc[:,0].astype('double')})
              f2 = pd.DataFrame({'price':cusdata.iloc[:,1].astype('double')})
  
              T = (end-start) / 252 
  
              corr = getcorr(f1, f2, T)
              corr.append(' / '.join(list(pair)))
              rhodata.append(corr)
  
          spotdata = []
          spots = list(set(spot1+spot2))
          for i in range(len(spots)):
              spotval = pd.DataFrame({'price':cusdata.iloc[:,i].astype('double')})
              spotdata.append([spotval, spots[i]])
  
          instcorrdiv = instvol.myplotly.getcorrdiv(rhodata)
          hiscorrdiv = instvol.myplotly.getcorrdiv(rhodata, isHis=1)
          spotdiv = instvol.myplotly.getspotdiv(spotdata)
  
      else:
          spot1 = request.GET.getlist('field-a')
          spot2 = request.GET.getlist('field-b')
          symbolPair = list(zip(spot1, spot2))
          daterange = request.GET.get('daterange', 'None')
  
          if len(symbolPair) == 0:
              symbolPair = [['SPX','NDWLIT'], ['SPX', 'FTMIGMI'], ['SPX','GBIEMDCW']]
              spot1 = list(zip(*symbolPair))[0]
              spot2 = list(zip(*symbolPair))[1]
              if daterange == 'None':
                  context = pickle.load(open( "defaultcorr_context.p", "rb" ))
                  template = loader.get_template('instvol/correlation.html')
                  return HttpResponse(template.render(context, request))
  
          daterange = daterange.replace(' ','').split('-')
          start = datetime.datetime.strptime(daterange[0], '%Y%m%d')
          end = datetime.datetime.strptime(daterange[1], '%Y%m%d')
  
          rhodata = []
          for pair in symbolPair:
              f1 = Stock.objects.get(ticker=pair[0]).stockprice_set.filter(ts__gte=start.date(), ts__lte=end.date())
              f1 = pd.DataFrame(list(f1.values())).set_index('ts').astype('float').dropna()
              f1.index = pd.to_datetime(f1.index.date)
              f2 = Stock.objects.get(ticker=pair[1]).stockprice_set.filter(ts__gte=start.date(), ts__lte=end.date())
              f2 = pd.DataFrame(list(f2.values())).set_index('ts').astype('float').dropna()
              f2.index = pd.to_datetime(f2.index.date)
              commonidx = f1.index.intersection(f2.index)
              f1 = f1.loc[commonidx]
              f2 = f2.loc[commonidx]
  
              T = (end-start).days / 252 
  
              corr = getcorr(f1, f2, T)
              corr.append(' / '.join(list(pair)))
              rhodata.append(corr)
  
          spotdata = []
          for spot in list(set(spot1+spot2)):
              spotval = Stock.objects.get(ticker=spot).stockprice_set.filter(ts__gte=start.date(), ts__lte=end.date())
              spotval = pd.DataFrame(list(spotval.values()))
              spotval = spotval.set_index('ts').astype('float').dropna()
              spotval.index = pd.to_datetime(spotval.index.date)
              spotdata.append([spotval, spot])
  
          instcorrdiv = instvol.myplotly.getcorrdiv(rhodata)
          hiscorrdiv = instvol.myplotly.getcorrdiv(rhodata, isHis=1)
          spotdiv = instvol.myplotly.getspotdiv(spotdata)
  
          form = UploadFileForm()
  
      template = loader.get_template('instvol/correlation.html')
  
      context = {'plot_div_inst': instcorrdiv, 'plot_div_his': hiscorrdiv, 'plot_div_spot': spotdiv,  'ticker_list': tickers, 'form': form}
  
      return HttpResponse(template.render(context, request))
  </code></pre>
  
  <p>And <strong>forms.py</strong>:</p>
  
  <p>from django import forms</p>
  
  <pre><code>class UploadFileForm(forms.Form):
      # title = forms.CharField(max_length=50)
      file = forms.FileField()
  </code></pre>