title: UnboundLocalError- local variable referenced before assignment - Django
body: <p>You guys have helped me out so much this week it has been awesome.Hopefully you can help me out with this one. I tried looking at the other posts on the site about this type of error, but none of them really helped me out. Basically I am submitting a form on one page and the POST data is going to the same view that it was generated with. I want to redirect to an other page after the POST data is sent, but I get this error.</p>
  
  <pre><code>def test(request):
      if request.method == 'POST':
          form = SubmitForm(request.POST) # A form bound to the POST data
          if form.is_valid():
              lat = form.cleaned_data['lat'] 
              lng = form.cleaned_data['lng']
              title = form.cleaned_data['title']
              story = form.cleaned_data['story']
  
              ctxt = {
                      'lat':lat,
                      'lng':lng,
                      'title':title,
                      'story':story,
                      }
  
              return render_to_response('home.html', ctxt, context_instance=RequestContext(request)) 
  
      else:
  
          import datetime
          now = datetime.datetime.now()
          form = SubmitForm()
          latest_marks = Marker.objects.all().order_by('-submitted')[0:10]
  
          ctxt = {
                  'marks':latest_marks,
                  'now':now.date(),
                  'form': form,
                  }
      return render_to_response('test.html', ctxt, context_instance=RequestContext(request)) 
  </code></pre>
  
  <p>The error I get is </p>
  
  <pre><code>local variable 'ctxt' referenced before assignment
  </code></pre>
  
  <p>And the traceback is </p>
  
  <pre><code>Environment:
  
  
  Request Method: POST
  Request URL: http://localhost:8000/test/
  
  Django Version: 1.3
  Python Version: 2.6.5
  Installed Applications:
  ['django.contrib.staticfiles',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.sites',
   'django.contrib.admin',
   'userena',
   'guardian',
   'easy_thumbnails',
   'south',
   'database',
   'accounts',
   'socialregistration']
  Installed Middleware:
  ('django.middleware.common.CommonMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'userena.middleware.UserenaLocaleMiddleware',
   'socialregistration.middleware.FacebookMiddleware')
  
  
  Traceback:
  File "/home/wluw/dev/chicagomap/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py" in get_response
    111.                         response = callback(request, *callback_args, **callback_kwargs)
  File "/home/wluw/dev/chicagomap/chicagomap/../chicagomap/database/views.py" in test
    58.     return render_to_response('test.html', ctxt, context_instance=RequestContext(request)) 
  
  Exception Type: UnboundLocalError at /test/
  Exception Value: local variable 'ctxt' referenced before assignment
  </code></pre>
  
  <p>Any help would be greatly appreciated. Thanks.</p>