title: How to get the value of a hidden input in django views
body: <p>I am working on a django application. In the application, I have a drop-down button in a form. There also is a hidden input field that will hold the value of the drop-down item selected. (I achieved this with <code>jQuery</code>). I want to access the value of the hidden field in the views.py file.</p>
  
  <p>Right now when the form is submitted, I am only getting a None value returned. I am not sure what I am doing wrong. This is my code so far</p>
  
  <p>HTML template</p>
  
  <pre><code>&lt;form method="post" action="{% url 'test_app:get_data' %}"&gt;
      {% csrf_token %}
      &lt;div class="dropdown"&gt;
          &lt;button class="btn btn-primary btn-lg btn-block dropdown-toggle fruit-btn" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;
              Fruit
          &lt;/button&gt;
          &lt;input type="hidden" name="fruit-name" id="fruit-name" value="" disabled&gt;
          &lt;div class="dropdown-menu"&gt;
              &lt;ul class="list-group" role="menu" aria-labelledby="dropdownMenu"&gt;
                  &lt;li class='list-group-item'&gt;&lt;a class="btn btn-lg dropdown-item" href="#"&gt;Apple&lt;/a&gt;&lt;/li&gt;
                  &lt;li class='list-group-item'&gt;&lt;a class="btn btn-lg dropdown-item" href="#"&gt;Banana&lt;/a&gt;&lt;/li&gt;
                  &lt;li class='list-group-item'&gt;&lt;a class="btn btn-lg dropdown-item" href="#"&gt;Mango&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      ...
  
      &lt;button type="submit" class="btn btn-primary btn-block btn-lg mt-5"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def test_data(request):
      if request.method == 'POST':
          fruit = request.POST.get('fruit-name')
          print(fruit)
  
          return redirect("test_app:root")
  
      return render(request, 'test_app/root.html')
  </code></pre>
  
  <p>jquery code to get the value of the button in the hidden input field</p>
  
  <pre><code>$(document).ready(function() {
    $('.dropdown-item').click(function() {
      $('.fruit-btn').text($(this).text());
      $('.fruit-btn').val($(this).text());
      $('#fruit-name').val($(this).text());
      console.log($('#fruit-name').val())
    })
  })
  </code></pre>
  
  <p>This is the output of the jquery <code>console.log</code> when I click a particular fruit</p>
  
  <pre><code>Mango
  </code></pre>
  
  <p>This is the output of the python <code>print(fruit)</code> from <code>views.py</code> when I submit the form</p>
  
  <pre><code>None
  </code></pre>
  
  <p>I am not sure what I am doing wrong. Any suggestions?</p>