- Python Pyramid 教程
- Python Pyramid - 首页
- Python Pyramid - 概述
- Pyramid - 环境设置
- Python Pyramid - Hello World
- Pyramid - 应用配置
- Python Pyramid - URL 路由
- Python Pyramid - 视图配置
- Python Pyramid - 路由前缀
- Python Pyramid - 模板
- Pyramid - HTML 表单模板
- Python Pyramid - 静态资源
- Python Pyramid - 请求对象
- Python Pyramid - 响应对象
- Python Pyramid - 会话
- Python Pyramid - 事件
- Python Pyramid - 消息闪现
- Pyramid - 使用 SQLAlchemy
- Python Pyramid - Cookiecutter
- Python Pyramid - 创建项目
- Python Pyramid - 项目结构
- Python Pyramid - 包结构
- 手动创建项目
- 命令行 Pyramid
- Python Pyramid - 测试
- Python Pyramid - 日志记录
- Python Pyramid - 安全性
- Python Pyramid - 部署
- Python Pyramid 有用资源
- Python Pyramid - 快速指南
- Python Pyramid - 有用资源
- Python Pyramid - 讨论
Python Pyramid - 请求对象
视图可调用的功能包括从 WSGI 环境获取请求数据,并在处理后将特定的 HTTP 响应返回给客户端。视图函数接收 Request 对象作为参数。
通常,此对象不是由用户实例化的。相反,它封装了 WSGI environ 字典。此请求对象表示“pyramid.request.Request 类”。它拥有许多属性和方法,视图函数使用这些属性和方法来处理请求数据。
以下是一些属性:
request.method - 客户端用于发送数据的 HTTP 请求方法,例如 GET、POST
request.GET - 此属性是一个 multidict,包含查询字符串中的所有变量。
request.POST - 此属性仅在请求为 POST 且为表单提交时可用。它是一个 multidict,包含请求主体中的所有变量。
request.params - request.GET 和 request.POST 中所有内容的组合 multidict。
request.body - 此属性包含整个请求主体作为字符串。当请求为非表单提交的 POST 或 PUT 等请求时,这很有用。
request.cookies - 包含所有 Cookie。
request.headers - 所有 HTTP 标头的区分大小写的字典。
除了上述 HTTP 特定的环境属性外,Pyramid 还添加了一些特殊属性。
request.url - 返回包含查询字符串的完整请求 URL,例如 https://:6543/app?name=Ravi
request.host - URL 中的主机信息,例如 localhost
request.host_url - 此属性返回包含主机的 URL,例如 https://:6543/
request.application_url - 应用程序的 URL(不包括 PATH_INFO),例如 https://:6543/app
request.path_url - 包含应用程序的 URL,包括 PATH_INFO,例如 https://:66543/app
request.path - 返回包含 PATH_INFO 但不包括主机的 URL,例如 "/app"
request.path_qs - URL 中包含 PATH_INFO 的查询字符串,例如 "/app?name=Ravi"
request.query_string - 仅 URL 中的查询字符串,例如 "name=Ravi"