使用 Tipfy 获取 HTTP GET 变量

发布于 2024-08-27 08:56:19 字数 457 浏览 5 评论 0原文

我目前正在 Google 的 Appengine 上使用 tipfy,最近遇到了一个问题:我一生都找不到任何有关如何在应用程序中使用 GET 变量的文档,我尝试过筛选 tipfyWerkzeug 的 文档没有成功。我知道我可以使用 request.form.get('variable') 来获取 POST 变量,并在 URL 变量的处理程序中使用 **kwargs ,但这与文档会告诉我。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罗罗贝儿 2024-09-03 08:56:19

request.args.get('variable') 应该适用于我认为您所说的“获取数据”的意思。

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

你是年少的欢喜 2024-09-03 08:56:19

来源:http://www.tipfy.org/wiki/guide/request/

Request 对象包含应用程序客户端传输的所有信息。您将从中检索 GET 和 POST 值、上传的文件、cookie 和标头信息等。所有这些事情都很常见,你会很习惯的。

要访问 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

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
浊酒尽余欢 2024-09-03 08:56:19

这对我有用(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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文