title: Pass an initial value to a Django form field
body: <p>Django newbie question....</p>
  
  <p>I'm trying to write a search form and maintain the state of the input box between the search request and the search results.</p>
  
  <p>Here's my form:</p>
  
  <pre><code>class SearchForm(forms.Form):
      q = forms.CharField(label='Search: ', max_length=50)
  </code></pre>
  
  <p>And here's my views code:</p>
  
  <pre><code>def search(request, q=""):
      if (q != ""): 
          q = q.strip()
          form = SearchForm(initial=q) 
          #get results here...
          return render_to_response('things/search_results.html',
            {'things': things,  'form': form, 'query': q})
      elif (request.method == 'POST'): # If the form has been submitted
          form = SearchForm(request.POST) 
          if form.is_valid(): 
            q = form.cleaned_data['q']
            # Process the data in form.cleaned_data
            return HttpResponseRedirect('/things/search/%s/' % q) # Redirect after POST
          else:
            form = SearchForm() 
            return render_to_response('things/search.html', {
              'form': form,
            })
      else:
          form = SearchForm()
          return render_to_response('things/search.html', {
              'form': form,
          })
  </code></pre>
  
  <p>But this gives me the error: </p>
  
  <pre><code>Caught an exception while rendering: 'unicode' object has no attribute 'get'
  </code></pre>
  
  <p>How can I pass the initial value? Various things I've tried seem to interfere with the request.POST parameter. </p>