Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 65530c6176058f9b54858c3b4f6385e6 > files > 951

python-django-doc-1.8.19-1.mga6.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" lang="">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>View decorators &#8212; Django 1.8.19 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.8.19',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="top" title="Django 1.8.19 documentation" href="../../contents.html" />
    <link rel="up" title="Handling HTTP requests" href="index.html" />
    <link rel="next" title="File Uploads" href="file-uploads.html" />
    <link rel="prev" title="Writing views" href="views.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body role="document">

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.8.19 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="views.html" title="Writing views">previous</a>
     |
    <a href="../index.html" title="Using Django" accesskey="U">up</a>
   |
    <a href="file-uploads.html" title="File Uploads">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="topics-http-decorators">
            
  <div class="section" id="s-module-django.views.decorators.http">
<span id="s-view-decorators"></span><span id="module-django.views.decorators.http"></span><span id="view-decorators"></span><h1>View decorators<a class="headerlink" href="#module-django.views.decorators.http" title="Permalink to this headline">¶</a></h1>
<p>Django provides several decorators that can be applied to views to support
various HTTP features.</p>
<div class="section" id="s-allowed-http-methods">
<span id="allowed-http-methods"></span><h2>Allowed HTTP methods<a class="headerlink" href="#allowed-http-methods" title="Permalink to this headline">¶</a></h2>
<p>The decorators in <a class="reference internal" href="#module-django.views.decorators.http" title="django.views.decorators.http"><code class="xref py py-mod docutils literal"><span class="pre">django.views.decorators.http</span></code></a> can be used to restrict
access to views based on the request method. These decorators will return
a <a class="reference internal" href="../../ref/request-response.html#django.http.HttpResponseNotAllowed" title="django.http.HttpResponseNotAllowed"><code class="xref py py-class docutils literal"><span class="pre">django.http.HttpResponseNotAllowed</span></code></a> if the conditions are not met.</p>
<dl class="function">
<dt id="django.views.decorators.http.require_http_methods">
<code class="descname">require_http_methods</code>(<em>request_method_list</em>)<a class="reference internal" href="../../_modules/django/views/decorators/http.html#require_http_methods"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.views.decorators.http.require_http_methods" title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to require that a view only accepts particular request
methods. Usage:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.views.decorators.http</span> <span class="k">import</span> <span class="n">require_http_methods</span>

<span class="nd">@require_http_methods</span><span class="p">([</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="s2">&quot;POST&quot;</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="c1"># I can assume now that only GET or POST requests make it this far</span>
    <span class="c1"># ...</span>
    <span class="k">pass</span>
</pre></div>
</div>
<p>Note that request methods should be in uppercase.</p>
</dd></dl>

<dl class="function">
<dt id="django.views.decorators.http.require_GET">
<code class="descname">require_GET</code>()<a class="headerlink" href="#django.views.decorators.http.require_GET" title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to require that a view only accepts the GET method.</p>
</dd></dl>

<dl class="function">
<dt id="django.views.decorators.http.require_POST">
<code class="descname">require_POST</code>()<a class="headerlink" href="#django.views.decorators.http.require_POST" title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to require that a view only accepts the POST method.</p>
</dd></dl>

<dl class="function">
<dt id="django.views.decorators.http.require_safe">
<code class="descname">require_safe</code>()<a class="headerlink" href="#django.views.decorators.http.require_safe" title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to require that a view only accepts the GET and HEAD methods.
These methods are commonly considered &#8220;safe&#8221; because they should not have
the significance of taking an action other than retrieving the requested
resource.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Django will automatically strip the content of responses to HEAD
requests while leaving the headers unchanged, so you may handle HEAD
requests exactly like GET requests in your views. Since some software,
such as link checkers, rely on HEAD requests, you might prefer
using <code class="docutils literal"><span class="pre">require_safe</span></code> instead of <code class="docutils literal"><span class="pre">require_GET</span></code>.</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-conditional-view-processing">
<span id="conditional-view-processing"></span><h2>Conditional view processing<a class="headerlink" href="#conditional-view-processing" title="Permalink to this headline">¶</a></h2>
<p>The following decorators in <a class="reference internal" href="#module-django.views.decorators.http" title="django.views.decorators.http"><code class="xref py py-mod docutils literal"><span class="pre">django.views.decorators.http</span></code></a> can be used to
control caching behavior on particular views.</p>
<dl class="function">
<dt id="django.views.decorators.http.condition">
<code class="descname">condition</code>(<em>etag_func=None</em>, <em>last_modified_func=None</em>)<a class="reference internal" href="../../_modules/django/views/decorators/http.html#condition"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.views.decorators.http.condition" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="django.views.decorators.http.etag">
<code class="descname">etag</code>(<em>etag_func</em>)<a class="reference internal" href="../../_modules/django/views/decorators/http.html#etag"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.views.decorators.http.etag" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="django.views.decorators.http.last_modified">
<code class="descname">last_modified</code>(<em>last_modified_func</em>)<a class="reference internal" href="../../_modules/django/views/decorators/http.html#last_modified"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.views.decorators.http.last_modified" title="Permalink to this definition">¶</a></dt>
<dd><p>These decorators can be used to generate <code class="docutils literal"><span class="pre">ETag</span></code> and <code class="docutils literal"><span class="pre">Last-Modified</span></code>
headers; see
<a class="reference internal" href="../conditional-view-processing.html"><span class="doc">conditional view processing</span></a>.</p>
</dd></dl>

<span class="target" id="module-django.views.decorators.gzip"></span></div>
<div class="section" id="s-gzip-compression">
<span id="gzip-compression"></span><h2>GZip compression<a class="headerlink" href="#gzip-compression" title="Permalink to this headline">¶</a></h2>
<p>The decorators in <a class="reference internal" href="#module-django.views.decorators.gzip" title="django.views.decorators.gzip"><code class="xref py py-mod docutils literal"><span class="pre">django.views.decorators.gzip</span></code></a> control content
compression on a per-view basis.</p>
<dl class="function">
<dt id="django.views.decorators.gzip.gzip_page">
<code class="descname">gzip_page</code>()<a class="headerlink" href="#django.views.decorators.gzip.gzip_page" title="Permalink to this definition">¶</a></dt>
<dd><p>This decorator compresses content if the browser allows gzip compression.
It sets the <code class="docutils literal"><span class="pre">Vary</span></code> header accordingly, so that caches will base their
storage on the <code class="docutils literal"><span class="pre">Accept-Encoding</span></code> header.</p>
</dd></dl>

<span class="target" id="module-django.views.decorators.vary"></span></div>
<div class="section" id="s-vary-headers">
<span id="vary-headers"></span><h2>Vary headers<a class="headerlink" href="#vary-headers" title="Permalink to this headline">¶</a></h2>
<p>The decorators in <a class="reference internal" href="#module-django.views.decorators.vary" title="django.views.decorators.vary"><code class="xref py py-mod docutils literal"><span class="pre">django.views.decorators.vary</span></code></a> can be used to control
caching based on specific request headers.</p>
<dl class="function">
<dt id="django.views.decorators.vary.vary_on_cookie">
<code class="descname">vary_on_cookie</code>(<em>func</em>)<a class="headerlink" href="#django.views.decorators.vary.vary_on_cookie" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="django.views.decorators.vary.vary_on_headers">
<code class="descname">vary_on_headers</code>(<em>*headers</em>)<a class="headerlink" href="#django.views.decorators.vary.vary_on_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>The <code class="docutils literal"><span class="pre">Vary</span></code> header defines which request headers a cache mechanism should take
into account when building its cache key.</p>
<p>See <a class="reference internal" href="../cache.html#using-vary-headers"><span class="std std-ref">using vary headers</span></a>.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">View decorators</a><ul>
<li><a class="reference internal" href="#allowed-http-methods">Allowed HTTP methods</a></li>
<li><a class="reference internal" href="#conditional-view-processing">Conditional view processing</a></li>
<li><a class="reference internal" href="#gzip-compression">GZip compression</a></li>
<li><a class="reference internal" href="#vary-headers">Vary headers</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="views.html">Writing views</a></li>
    
    
      <li>Next: <a href="file-uploads.html">File Uploads</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../index.html">Django 1.8.19 documentation</a>
        
          <ul><li><a href="../index.html">Using Django</a>
        
          <ul><li><a href="index.html">Handling HTTP requests</a>
        
        <ul><li>View decorators</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/topics/http/decorators.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Mar 10, 2018</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="views.html" title="Writing views">previous</a>
     |
    <a href="../index.html" title="Using Django" accesskey="U">up</a>
   |
    <a href="file-uploads.html" title="File Uploads">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>