"if user:" is indented when it shouldn't be.

Indentation is part of the Python syntax, so be mindful of it when coding.

Nick
On Nov 29, 2012 12:35 PM, "Redas Nekrosius" <[email protected]> wrote:

> Hello,
> can anyone tell me the difference between two code snippets please:
> *1.*
> import webapp2
>
> from google.appengine.api import users
>
> class MainPage(webapp2.RequestHandler):
>   def get(self):
>     user = users.get_current_user()
>  if user:
>   self.response.headers['Content-Type'] = 'text/plain'
>   self.response.out.write('Hello, ' + user.nickname())
>     else:
>   self.redirect(users.create_login_url(self.request.uri))
>
> app = webapp2.WSGIApplication([('/', MainPage)],
>                               debug=True)
>
> *2.*
>
> import webapp2
>
> from google.appengine.api import users
>
> class MainPage(webapp2.RequestHandler):
>   def get(self):
>     user = users.get_current_user()
>
>     if user:
>       self.response.headers['Content-Type'] = 'text/plain'
>       self.response.out.write('Hello, ' + user.nickname())
>     else:
>       self.redirect(users.create_login_url(self.request.uri))
>
> app = webapp2.WSGIApplication([('/', MainPage)],
>                               debug=True)
>
> *
> *
> 1. Doesn't work
> 2. Does work
>
> Can't figure out the reason why is that.
>
> Thank you.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/DQYI8a_MJyIJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to