Steve Gattuso
Steve Gattuso

Reputation: 7832

Getting HTTP GET variables using Tipfy

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?

Upvotes: 2

Views: 1589

Answers (3)

Andrei Pall
Andrei Pall

Reputation: 1

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)

Upvotes: 0

PedroMorgan
PedroMorgan

Reputation: 936

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

Upvotes: 2

Alex Martelli
Alex Martelli

Reputation: 882591

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

Upvotes: 3

Related Questions