views:

336

answers:

3

Hey everyone,

I'm currently playing around with tipfy on Google's Appengine and just recently ran into a problem: I can't for the life of me find any documentation on how to use GET variables in my application, I've tried sifting through both tipfy and Werkzeug's documentations with no success. I know that I can use request.form.get('variable') to get POST variables and **kwargs in my handlers for URL variables, but that's as much as the documentation will tell me. Any ideas?

+3  A: 

request.args.get('variable') should work for what I think you mean by "GET data".

Alex Martelli
Yep that did the trick! Thanks a ton.
Vestonian
In tipfy's tutorials (http://www.tipfy.org/wiki/tutorials/sessions/), they use this syntax: request.args.get('variable', None)What is the extra 'None' for?
Wraith
@Wraith, they probably added it as an application of "explicit is better than implicit" -- in this case I disagree since I don't see it as explicit but redundant (but I do add an explicit, or redundant, `return None` at the end of functions that return other values along other paths). In any case, it's a strictly stylistic issue, with no semantic implications whatsoever.
Alex Martelli
Thank you, Alex.
Wraith
+1  A: 

Source: http://www.tipfy.org/wiki/guide/request/

The Request object contains all the information transmitted by the client of the application. You will retrieve from it GET and POST values, uploaded files, cookies and header information and more. All these things are so common that you will be very used to it.

To access the Request object, simply import the request variable from tipfy:

from tipfy import request

# GET
request.args.get('foo')

# POST
request.form.get('bar')

# FILES
image = request.files.get('image_upload')
if image:
    # User uploaded a file. Process it.

    # This is the filename as uploaded by the user.
    filename = image.filename

    # This is the file data to process and/or save.
    filedata = image.read()
else:
    # User didn't select any file. Show an error if it is required.
    pass
PedroMorgan
A: 

this works for me (tipfy 0.6):

from tipfy import RequestHandler, Response

from tipfy.ext.session import SessionMiddleware, SessionMixin

from tipfy.ext.jinja2 import render_response

from tipfy import Tipfy

class I18nHandler(RequestHandler, SessionMixin):
    middleware = [SessionMiddleware]
    def get(self):
        language = Tipfy.request.args.get('lang')
        return render_response('hello_world.html', message=language)
Andrei Pall