0

I have written a code for a sign-up page asking for information like username, password and email. After the user gives correct input, the page is redirected to

'/welcome?username=name'

I am using the self.redirect. By using the methd redirect, I am getting the the new URL as '/welcome'. How will I include the query parameter? I also want the user_name to be displayed to the redirected page like :

Welcome name

How will I do this? This is the class I have written to handle '/welcome'

class welcomeHandler(webapp2.RequestHandler):
    def get(self):
        self.response.out.write("Welcome")

app = webapp2.WSGIApplication([
    ('/', MainHandler),('/welcome',welcomeHandler)], debug=True)
Ivan
  • 19,560
  • 31
  • 97
  • 141

3 Answers3

2

If you need to encode it, you can use this:

import urllib
self.redirect('/welcome?' + urllib.urlencode({'username': name})

If you ever need to add more query parameters, just add them to the dictionary, as shown in How to urlencode a querystring in Python?.

setnoset
  • 249
  • 3
  • 7
1

You need to use string substitution. Suppose you are storing the username in name. Thus you need to write :

self.redirect("/Welcome/username="+name)
Richa Tibrewal
  • 468
  • 7
  • 26
0

Why would you want to handle the user greeting like that? Either pass it as a template variable or do it as following:

class welcomeHandler(webapp2.RequestHandler):
    def get(self):
        self.response.out.write("Welcome %s") % username

Also, make sure you create a session for the user once they've signed up, otherwise you're just creating their credential but not actually logging them in.

Borko Kovacev
  • 1,010
  • 2
  • 14
  • 33