title: Django/Python: How to pass a variable from a form to a python script with POST method?
body: <p>I'm getting this error when  submit: </p>
  
  <pre><code>CSRF verification failed. Request aborted.
  </code></pre>
  
  <p>I've got this far following the documentation, but I don't fully understand it and it's definitely wrong. I just want to take a query word from my search box(form) and pass it to a python script as an argument. I'm new to Django and getting stuck on the easiest things.</p>
  
  <p>In models.py:</p>
  
  <pre><code>class QueryForm(forms.Form):
      query = forms.CharField(label='query',max_length=100)
  </code></pre>
  
  <p>I added this line to my urls.py</p>
  
  <pre><code>url(r'^results/$', 'tweemo.views.results'),
  </code></pre>
  
  <p>On my homepage where my search box is I have this code for my form:</p>
  
  <pre><code>&lt;form action="/home/results/" method="post"&gt;
      &lt;label for="query"&gt;Search:&lt;/label&gt;
      &lt;input id="query" type="text" name="query" value="{{ current_query }}"&gt;
      &lt;input type="submit" value="ok"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In views.py I added these two functions:</p>
  
  <pre><code>def get_query(request):
      if request.method == 'POST':
          form = QueryForm(request.POST)
          if form.isvalid():
               return HttpResponseRedirect('/thanks/')
      else:
           form = QueryForm()
      return render(request, 'results.html', {'form': form})
  
  def results(request):
      return render_to_response('results.html',{'here':TwitterStream.objects.all() })
  </code></pre>
  
  <p>MY results.html contains just this:</p>
  
  <pre><code>&lt;form action="/home/results/" method="post"&gt;
      {% csrf_token %}
      {{ form }}
      &lt;input type="submit" value="Submit"/&gt;
  &lt;/form&gt;
  </code></pre>