使用Tipfy获取HTTP GET变量
3 个回答
0
这个对我有效(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)
2
来源: http://www.tipfy.org/wiki/guide/request/
Request对象包含了应用程序客户端发送的所有信息。你可以从中获取GET和POST的值、上传的文件、cookies(小数据文件)以及头部信息等等。这些内容非常常见,你会很快习惯它们。
要访问Request对象,只需从tipfy中导入request变量即可:
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
3
request.args.get('variable')
这个代码应该能满足你所说的“获取数据”的需求。