
- 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"