title: How do I access a variable in views.py using jQuery/AJAX?
body: <h1>edit</h1>
  <p>When I write print request.POST['video'], nothing gets printed in the console even through there is a value for 'video'. Am I incorrectly getting the wrong value in the javascript? I am trying to get the 'video34' (the value in the hidden field) to show up.</p>
  <h1>original</h1>
  <p>I am trying to POST data using jQuery/AJAX in Django and am having trouble.  How do I access the 'video' variable in the views.py?  When I write 'print video' in views.py, I get an error in the console saying POST /edit_favorites/ HTTP/1.1&quot; 500 10113.</p>
  <h1>views.py</h1>
  <pre><code>from django.shortcuts import render_to_response
  from django.http import HttpResponse
  from django.views.decorators.csrf import csrf_exempt
  
  @csrf_exempt
  def edit_favorites(request):
      if request.is_ajax():
          message = &quot;Yes, AJAX!&quot;
      else:
          message = &quot;Not Ajax&quot;
      return HttpResponse(message)
  </code></pre>
  <h1>urlconf:</h1>
  <pre><code>url(r'^edit_favorites/', 'edit_favorites'),
  </code></pre>
  <h1>html:</h1>
  <pre><code>&lt;form method='post' id ='test'&gt;
       &lt;input type=&quot;hidden&quot; value=&quot;video34&quot; /&gt;
      &lt;input type='submit' value='Test button'/&gt;
      
      &lt;div id = 'message'&gt;Initial text&lt;/div&gt;
          
  &lt;/form&gt;
  </code></pre>
  <h1>javascript:</h1>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
     $(document).ready(function() {
         $(&quot;#test&quot;).submit(function(event){
         event.preventDefault();
              $.ajax({
                   type:&quot;POST&quot;,
                   url:&quot;/edit_favorites/&quot;,
                   data: {
                          'video': $('#test').val() // from form
                          },
                   success: function(){
                       $('#message').html(&quot;&lt;h2&gt;Contact Form Submitted!&lt;/h2&gt;&quot;) 
                      }
              });
              return false;
         });
         
      });
  &lt;/script&gt;
  </code></pre>