Your line with the error is not guarded with an "if user:"
Star the request with an empty
template_values = {}
and add keys when you know they contain valid values
if user:
template_values['userName'] = user.nickname()
2010/8/20 brent <[email protected]>:
> hi everyone:
>
> am new here, please help me fix this problem.
> thank a lot.
>
> error
> ##################################
> Traceback (most recent call last):
> File "C:\Program
> Files\Google\google_appengine\google\appengine\ext\webapp
> \__init__.py",
> line 511, in __call__
> handler.get(*groups)
> File "D:\__web\sites\test\main.py", line 21, in get
> 'userName': user.nickname(),
> AttributeError: 'NoneType' object has no attribute 'nickname'
>
> #######################################
>
> #!/usr/bin/env python
>
> import cgi
> import os
> from google.appengine.api import users
> from google.appengine.ext import webapp
> from google.appengine.ext.webapp.util import run_wsgi_app
> from google.appengine.ext.webapp import template
>
> class MainPage(webapp.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()) ### No
> Error Here
> else:
> self.redirect(users.create_login_url(self.request.uri))
>
> template_values = {
> 'userName': user.nickname(), ############line 21, error
> here.
> 'mail': "345",
> }
>
> path = os.path.join(os.path.dirname(__file__), 'index.html')
> # self.response.out.write(template.render(path, template_values))
>
> application = webapp.WSGIApplication([('/', MainPage)], debug=True)
>
> def main():
> run_wsgi_app(application)
>
> if __name__ == "__main__":
> main()
--
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.