<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 視圖裝飾器 # Django為視圖提供了數個裝飾器,用以支持相關的HTTP服務。 ## 允許的HTTP 方法 ## `django.views.decorators.http` 包里的裝飾器可以基于請求的方法來限制對視圖的訪問。若條件不滿足會返回 `django.http.HttpResponseNotAllowed`。 `require_http_methods`(request_method_list)[source] 限制視圖只能服務規定的http方法。用法: ``` from django.views.decorators.http import require_http_methods @require_http_methods(["GET", "POST"]) def my_view(request): # I can assume now that only GET or POST requests make it this far # ... pass ``` 注意,方法名必須大寫。 `require_GET()` 只允許視圖接受GET方法的裝飾器。 `require_POST()` 只允許視圖接受POST方法的裝飾器。 `require_safe()` 只允許視圖接受 GET 和 HEAD 方法的裝飾器。 這些方法通常被認為是安全的,因為方法不該有請求資源以外的目的。 > 注 > > Django 會自動清除對HEAD 請求的響應中的內容而只保留頭部,所以在你的視圖中你處理HEAD 請求的方式可以完全與GET 請求一致。因為某些軟件,例如鏈接檢查器,依賴于HEAD 請求,所以你可能應該使用`require_safe` 而不是`require_GET`。 ## 可控制的視圖處理 ## `django.views.decorators.http` 中的以下裝飾器可以用來控制特定視圖的緩存行為。 `condition`(etag_func=None, last_modified_func=None)[source] `etag`(etag_func)[source] `last_modified`(last_modified_func)[source] 這些裝飾器可以用于生成ETag 和Last-Modified 頭部;參考 conditional view processing. ## GZip 壓縮 ## `django.views.decorators.gzip` 里的裝飾器基于每個視圖控制其內容壓縮。 `gzip_page()` 如果瀏覽器允許gzip 壓縮,這個裝飾器將對內容進行壓縮。它設置相應的`Vary`頭部,以使得緩存根據`Accept-Encoding`頭來存儲信息。 ## Vary 頭部 ## `django.views.decorators.vary` 可以用來基于特定的請求頭部來控制緩存。 `vary_on_cookie`(func)[source] `vary_on_headers`(\*headers)[source] 到當構建緩存的鍵時,Vary 頭部定義一個緩存機制應該考慮的請求頭。 參見[使用vary 頭部](http://python.usyiyi.cn/django/topics/cache.html#using-vary-headers)。 > 譯者:[Django 文檔協作翻譯小組](http://python.usyiyi.cn/django/index.html),原文:[Decorators](https://docs.djangoproject.com/en/1.8/topics/http/decorators/)。 > > 本文以 [CC BY-NC-SA 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/cn/) 協議發布,轉載請保留作者署名和文章出處。 > > [Django 文檔協作翻譯小組](http://python.usyiyi.cn/django/index.html)人手緊缺,有興趣的朋友可以加入我們,完全公益性質。交流群:467338606。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看