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?
Asked
Active
Viewed 1,584 times
2

Bill the Lizard
- 398,270
- 210
- 566
- 880

Steve Gattuso
- 7,644
- 10
- 44
- 59
-
What are you considering the difference between URL variables and GET variables? – Amber Apr 03 '10 at 01:02
3 Answers
3
request.args.get('variable')
should work for what I think you mean by "GET data".

Alex Martelli
- 854,459
- 170
- 1,222
- 1,395
-
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? – Matt Norris Jun 05 '10 at 20:28
-
@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 Jun 06 '10 at 00:53
2
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
- 926
- 12
- 15
0
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)

Martijn Pieters
- 1,048,767
- 296
- 4,058
- 3,343

Andrei Pall
- 1
- 1