Saikat Deshmukh
Saikat Deshmukh

Reputation: 63

How to use Users service of google app engine with the bottle.py framework?

I am trying to use the users service of GAE to integrate with Google Account.This is my code.

from framework import bottle
from framework.bottle import route, template, request, error, debug
from google.appengine.ext.webapp.util import run_wsgi_app 
from google.appengine.api import users



@route('/')
def DisplayForm():
    if user:
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, ' + user.nickname())
    else:
        self.redirect(users.create_login_url(self.request.uri))


if __name__=="__main__":
    main()

This code throws an error:

File "/home/saikat/Desktop/GOOG_PROJ/bgae/main.py", line 20, in DisplayForm
    self.redirect(users.create_login_url(self.request.uri))
NameError: global name 'self' is not defined

Adding self as a parameter in DisplayForm() does not help either.Any ideas on how to proceed? I am using python 2.7. Development environment is Ubuntu 12.04

Upvotes: 0

Views: 120

Answers (1)

OrionMelt
OrionMelt

Reputation: 2601

Import response and redirect from bottle and remove self in DisplayForm.

from framework.bottle import route, template, request, error, debug, response, redirect

In DisplayForm:

if user:
    response.headers['Content-Type'] = 'text/plain'
    response.write('Hello, ' + user.nickname())
else:
    redirect(users.create_login_url(request.url))

Upvotes: 1

Related Questions