title: Unboundlocal Error Google App Engine
body: <p>I'm writing a blog app with SEO friendly urls.  When I visit an invalid url I get the following error:</p>
  
  <blockquote>
    <p>UnboundLocalError: local variable 'path' referenced before assignment</p>
  </blockquote>
  
  <p>valid urls work fine.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>class ViewPost(BaseHandler):
      def get(self, slug):
          post = Posts.all()
          post.filter('path =', slug)
          results = post.fetch(1)
          for post in results:
              path = post.path
          if path == slug:
              self.render_template('post.html', {'post':post})
          else:
              self.response.out.write('no post with this slug')
  </code></pre>
  
  <p>Here are examples of a <a href="http://busilinks.appspot.com/2012/05/first-post" rel="nofollow">valid</a> with no error, and a <a href="http://busilinks.appspot.com/2012/05/junk" rel="nofollow">invalid</a> that throws the error.  You can see the complete stack trace on the <a href="http://busilinks.appspot.com/2012/05/junk" rel="nofollow">invalid</a> example.</p>
  
  <p>The complete code is on <a href="https://github.com/buslinks/myblog/blob/master/views.py" rel="nofollow">github</a> line 62.</p>
  
  <p>Thanks in advance.  I'm new to python so I really appreciate your help and feedback.</p>
  
  <p><strong>Update</strong></p>
  
  <ol>
  <li><p>For context, I'm comparing two strings to determine if I have content to serve.</p></li>
  <li><p>What I expect to see: If the slug and path are equal , it should renders the template.  If not equal: It is supposed to respond with 'no post with this slug' message.</p></li>
  <li><p>Other things I've done.</p>
  
  <ul>
  <li><p>I've verified that I get a slug and path value.</p></li>
  <li><p>I've tried changing the idention like this.</p></li>
  </ul></li>
  </ol>
  
  <p>This stops me from getting the error, but I don't get my else response.  Instead I get a blank page with nothing in view source.</p>
  
  <pre><code>class ViewPost(BaseHandler):
  def get(self, slug):
      post = Posts.all()
      post.filter('path =', slug)
      results = post.fetch(1)
      for post in results:
          path = post.path
          if path == slug:
              self.render_template('post.html', {'post':post})
          else:
              self.response.out.write('no post with this slug')
  </code></pre>