{"title":"Middleware","version":"1.11","locale":"es","docname":"ref/middleware","url":"/es/1.11/ref/middleware/","canonical":"https://djangodocs.dev/es/1.11/ref/middleware/","summary":"This document explains all middleware components that come with Django. For information on how to use them and how to write your own middleware, see the middleware…","html":"<span id=\"middleware\"></span><h1>Middleware<a class=\"heading-anchor\" href=\"#module-django.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This document explains all middleware components that come with Django. For\ninformation on how to use them and how to write your own middleware, see\nthe <a class=\"reference internal\" href=\"/es/1.11/topics/http/middleware/\"><span class=\"doc\">middleware usage guide</span></a>.</p>\n<section id=\"available-middleware\">\n<h2>Available middleware<a class=\"heading-anchor\" href=\"#available-middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"module-django.middleware.cache\">\n<span id=\"cache-middleware\"></span><h3>Cache middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.cache\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.cache.UpdateCacheMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">UpdateCacheMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.cache.UpdateCacheMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.cache.FetchFromCacheMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">FetchFromCacheMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.cache.FetchFromCacheMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Enable the site-wide cache. If these are enabled, each Django-powered page will\nbe cached for as long as the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-CACHE_MIDDLEWARE_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHE_MIDDLEWARE_SECONDS</span></code></a> setting\ndefines. See the <a class=\"reference internal\" href=\"/es/1.11/topics/cache/\"><span class=\"doc\">cache documentation</span></a>.</p>\n</section>\n<section id=\"module-django.middleware.common\">\n<span id=\"common-middleware\"></span><h3>«Common» middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.common\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.common.CommonMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">CommonMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.common.CommonMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds a few conveniences for perfectionists:</p>\n<ul>\n<li><p>Forbids access to user agents in the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-DISALLOWED_USER_AGENTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DISALLOWED_USER_AGENTS</span></code></a>\nsetting, which should be a list of compiled regular expression objects.</p></li>\n<li><p>Performs URL rewriting based on the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> and\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a> settings.</p>\n<p>If <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> and the initial URL doesn’t end\nwith a slash, and it is not found in the URLconf, then a new URL is\nformed by appending a slash at the end. If this new URL is found in the\nURLconf, then Django redirects the request to this new URL. Otherwise,\nthe initial URL is processed as usual.</p>\n<p>For example, <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar</span></code> will be redirected to <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar/</span></code> if\nyou don’t have a valid URL pattern for <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar</span></code> but <em>do</em> have a\nvalid pattern for <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar/</span></code>.</p>\n<p>If <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, URLs that lack a leading «www.»\nwill be redirected to the same URL with a leading «www.»</p>\n<p>Both of these options are meant to normalize URLs. The philosophy is that\neach URL should exist in one, and only one, place. Technically a URL\n<code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar</span></code> is distinct from <code class=\"docutils literal notranslate\"><span class=\"pre\">foo.com/bar/</span></code> – a search-engine\nindexer would treat them as separate URLs – so it’s best practice to\nnormalize URLs.</p>\n</li>\n<li><p>Handles ETags based on the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-USE_ETAGS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_ETAGS</span></code></a> setting. If\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-USE_ETAGS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_ETAGS</span></code></a> is set to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, Django will calculate an ETag\nfor each request by MD5-hashing the page content, and it’ll take care of\nsending <code class=\"docutils literal notranslate\"><span class=\"pre\">Not</span> <span class=\"pre\">Modified</span></code> responses, if appropriate.</p></li>\n<li><p>Sets the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Length</span></code> header for non-streaming responses.</p></li>\n</ul>\n<aside class=\"version-note version-changed\" data-version=\"1.11\">\n<p class=\"version-note-title\">Changed in Django 1.11</p><p>Older versions didn’t set the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Length</span></code> header.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"1.11\">\n<p class=\"version-note-title\">Deprecated since Django 1.11</p><p><span class=\"versionmodified deprecated\">Obsoleto desde la versión 1.11: </span>The <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-USE_ETAGS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_ETAGS</span></code></a> setting is deprecated in favor of using\n<a class=\"reference internal\" href=\"#django.middleware.http.ConditionalGetMiddleware\" title=\"django.middleware.http.ConditionalGetMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ConditionalGetMiddleware</span></code></a> for ETag\nprocessing.</p>\n</aside>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.common.CommonMiddleware.response_redirect_class\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">CommonMiddleware.</span></span><span class=\"sig-name descname\"><span class=\"pre\">response_redirect_class</span></span><a class=\"heading-anchor\" href=\"#django.middleware.common.CommonMiddleware.response_redirect_class\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Defaults to <a class=\"reference internal\" href=\"/es/1.11/ref/request-response/#django.http.HttpResponsePermanentRedirect\" title=\"django.http.HttpResponsePermanentRedirect\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponsePermanentRedirect</span></code></a>. Subclass\n<code class=\"docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code> and override the attribute to customize the redirects\nissued by the middleware.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.common.BrokenLinkEmailsMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">BrokenLinkEmailsMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.common.BrokenLinkEmailsMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<ul class=\"simple\">\n<li><p>Sends broken link notification emails to <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a> (see\n<a class=\"reference internal\" href=\"/es/1.11/howto/error-reporting/\"><span class=\"doc\">Error reporting</span></a>).</p></li>\n</ul>\n</section>\n<section id=\"module-django.middleware.gzip\">\n<span id=\"gzip-middleware\"></span><h3>GZip middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.gzip\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.gzip.GZipMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">GZipMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.gzip.GZipMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Advertencia</p>\n<p>Security researchers recently revealed that when compression techniques\n(including <code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code>) are used on a website, the site may become\nexposed to a number of possible attacks. Before using <code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code> on\nyour site, you should consider very carefully whether you are subject to\nthese attacks. If you’re in <em>any</em> doubt about whether you’re affected, you\nshould avoid using <code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code>. For more details, see the <a class=\"reference external\" href=\"http://breachattack.com/resources/BREACH%20-%20SSL,%20gone%20in%2030%20seconds.pdf\">the BREACH\npaper (PDF)</a> and <a class=\"reference external\" href=\"http://breachattack.com\">breachattack.com</a>.</p>\n</aside>\n<p>Compresses content for browsers that understand GZip compression (all modern\nbrowsers).</p>\n<p>This middleware should be placed before any other middleware that need to\nread or write the response body so that compression happens afterward.</p>\n<p>It will NOT compress content if any of the following are true:</p>\n<ul class=\"simple\">\n<li><p>The content body is less than 200 bytes long.</p></li>\n<li><p>The response has already set the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Encoding</span></code> header.</p></li>\n<li><p>The request (the browser) hasn’t sent an <code class=\"docutils literal notranslate\"><span class=\"pre\">Accept-Encoding</span></code> header\ncontaining <code class=\"docutils literal notranslate\"><span class=\"pre\">gzip</span></code>.</p></li>\n</ul>\n<p>If the response has an <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> header, the ETag is made weak to comply with\n<span class=\"target\" id=\"index-0\"></span><a class=\"rfc reference external\" href=\"https://datatracker.ietf.org/doc/html/rfc7232.html#section-2.1\"><strong>RFC 7232 Section 2.1</strong></a>.</p>\n<p>You can apply GZip compression to individual views using the\n<a class=\"reference internal\" href=\"/es/1.11/topics/http/decorators/#django.views.decorators.gzip.gzip_page\" title=\"django.views.decorators.gzip.gzip_page\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">gzip_page()</span></code></a> decorator.</p>\n<aside class=\"version-note version-changed\" data-version=\"1.10\">\n<p class=\"version-note-title\">Changed in Django 1.10</p><p>In older versions, Django’s CSRF protection mechanism was vulnerable to\nBREACH attacks when compression was used. This is no longer the case, but\nyou should still take care not to compromise your own secrets this way.</p>\n</aside>\n</section>\n<section id=\"module-django.middleware.http\">\n<span id=\"conditional-get-middleware\"></span><h3>Conditional GET middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.http\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.http.ConditionalGetMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">ConditionalGetMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.http.ConditionalGetMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Handles conditional GET operations. If the response doesn’t have an <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code>\nheader, the middleware adds one if needed. If the response has a <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Last-Modified</span></code> header, and the request has <code class=\"docutils literal notranslate\"><span class=\"pre\">If-None-Match</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">If-Modified-Since</span></code>, the response is replaced by an\n<a class=\"reference internal\" href=\"/es/1.11/ref/request-response/#django.http.HttpResponseNotModified\" title=\"django.http.HttpResponseNotModified\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseNotModified</span></code></a>.</p>\n<aside class=\"version-note version-changed\" data-version=\"1.11\">\n<p class=\"version-note-title\">Changed in Django 1.11</p><p>In older versions, the middleware set the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Length</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">Date</span></code>\nheaders and didn’t set the <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> header.</p>\n</aside>\n</section>\n<section id=\"module-django.middleware.locale\">\n<span id=\"locale-middleware\"></span><h3>Locale middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.locale\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.locale.LocaleMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">LocaleMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.locale.LocaleMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Enables language selection based on data from the request. It customizes\ncontent for each user. See the <a class=\"reference internal\" href=\"/es/1.11/topics/i18n/translation/\"><span class=\"doc\">internationalization documentation</span></a>.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.locale.LocaleMiddleware.response_redirect_class\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">LocaleMiddleware.</span></span><span class=\"sig-name descname\"><span class=\"pre\">response_redirect_class</span></span><a class=\"heading-anchor\" href=\"#django.middleware.locale.LocaleMiddleware.response_redirect_class\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Defaults to <a class=\"reference internal\" href=\"/es/1.11/ref/request-response/#django.http.HttpResponseRedirect\" title=\"django.http.HttpResponseRedirect\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseRedirect</span></code></a>. Subclass\n<code class=\"docutils literal notranslate\"><span class=\"pre\">LocaleMiddleware</span></code> and override the attribute to customize the redirects\nissued by the middleware.</p>\n</section>\n<section id=\"module-django.contrib.messages.middleware\">\n<span id=\"message-middleware\"></span><h3>Message middleware<a class=\"heading-anchor\" href=\"#module-django.contrib.messages.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.messages.middleware.MessageMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">MessageMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.messages.middleware.MessageMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Enables cookie- and session-based message support. See the\n<a class=\"reference internal\" href=\"/es/1.11/ref/contrib/messages/\"><span class=\"doc\">messages documentation</span></a>.</p>\n</section>\n<section id=\"module-django.middleware.security\">\n<span id=\"id1\"></span><span id=\"security-middleware\"></span><h3>Security middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.security\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Advertencia</p>\n<p>If your deployment situation allows, it’s usually a good idea to have your\nfront-end Web server perform the functionality provided by the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code>. That way, if there are requests that aren’t served\nby Django (such as static media or user-uploaded files), they will have\nthe same protections as requests to your Django application.</p>\n</aside>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.security.SecurityMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">SecurityMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.security.SecurityMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">django.middleware.security.SecurityMiddleware</span></code> provides several security\nenhancements to the request/response cycle. Each one can be independently\nenabled or disabled with a setting.</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_BROWSER_XSS_FILTER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_BROWSER_XSS_FILTER</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_CONTENT_TYPE_NOSNIFF\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_HSTS_INCLUDE_SUBDOMAINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_HSTS_PRELOAD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_PRELOAD</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_REDIRECT_EXEMPT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_SSL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_HOST</span></code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a></p></li>\n</ul>\n<section id=\"http-strict-transport-security\">\n<span id=\"id2\"></span><h4>HTTP Strict Transport Security<a class=\"heading-anchor\" href=\"#http-strict-transport-security\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>For sites that should only be accessed over HTTPS, you can instruct modern\nbrowsers to refuse to connect to your domain name via an insecure connection\n(for a given period of time) by setting the <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Strict_Transport_Security\">«Strict-Transport-Security»\nheader</a>. This reduces your exposure to some SSL-stripping man-in-the-middle\n(MITM) attacks.</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will set this header for you on all HTTPS responses if\nyou set the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span></code></a> setting to a non-zero integer value.</p>\n<p>When enabling HSTS, it’s a good idea to first use a small value for testing,\nfor example, <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_HSTS_SECONDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_SECONDS</span> <span class=\"pre\">=</span> <span class=\"pre\">3600</span></code></a> for one\nhour. Each time a Web browser sees the HSTS header from your site, it will\nrefuse to communicate non-securely (using HTTP) with your domain for the given\nperiod of time. Once you confirm that all assets are served securely on your\nsite (i.e. HSTS didn’t break anything), it’s a good idea to increase this value\nso that infrequent visitors will be protected (31536000 seconds, i.e. 1 year,\nis common).</p>\n<p>Additionally, if you set the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_HSTS_INCLUDE_SUBDOMAINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_INCLUDE_SUBDOMAINS</span></code></a> setting\nto <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will add the <code class=\"docutils literal notranslate\"><span class=\"pre\">includeSubDomains</span></code> directive\nto the <code class=\"docutils literal notranslate\"><span class=\"pre\">Strict-Transport-Security</span></code> header. This is recommended (assuming all\nsubdomains are served exclusively using HTTPS), otherwise your site may still\nbe vulnerable via an insecure connection to a subdomain.</p>\n<p>If you wish to submit your site to the <a class=\"reference external\" href=\"https://hstspreload.org/\">browser preload list</a>, set the\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_HSTS_PRELOAD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_HSTS_PRELOAD</span></code></a> setting to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>. That appends the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">preload</span></code> directive to the <code class=\"docutils literal notranslate\"><span class=\"pre\">Strict-Transport-Security</span></code> header.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Advertencia</p>\n<p>The HSTS policy applies to your entire domain, not just the URL of the\nresponse that you set the header on. Therefore, you should only use it if\nyour entire domain is served via HTTPS only.</p>\n<p>Browsers properly respecting the HSTS header will refuse to allow users to\nbypass warnings and connect to a site with an expired, self-signed, or\notherwise invalid SSL certificate. If you use HSTS, make sure your\ncertificates are in good shape and stay that way!</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>If you are deployed behind a load-balancer or reverse-proxy server, and the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Strict-Transport-Security</span></code> header is not being added to your responses,\nit may be because Django doesn’t realize that it’s on a secure connection;\nyou may need to set the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_PROXY_SSL_HEADER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code></a> setting.</p>\n</aside>\n</section>\n<section id=\"x-content-type-options-nosniff\">\n<span id=\"x-content-type-options\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">X-Content-Type-Options:</span> <span class=\"pre\">nosniff</span></code><a class=\"heading-anchor\" href=\"#x-content-type-options-nosniff\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Some browsers will try to guess the content types of the assets that they\nfetch, overriding the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Type</span></code> header. While this can help display\nsites with improperly configured servers, it can also pose a security\nrisk.</p>\n<p>If your site serves user-uploaded files, a malicious user could upload a\nspecially-crafted file that would be interpreted as HTML or JavaScript by\nthe browser when you expected it to be something harmless.</p>\n<p>To prevent the browser from guessing the content type and force it to\nalways use the type provided in the <code class=\"docutils literal notranslate\"><span class=\"pre\">Content-Type</span></code> header, you can pass\nthe <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options\">X-Content-Type-Options: nosniff</a> header.  <code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will\ndo this for all responses if the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_CONTENT_TYPE_NOSNIFF\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a> setting\nis <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n<p>Note that in most deployment situations where Django isn’t involved in serving\nuser-uploaded files, this setting won’t help you. For example, if your\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a> is served directly by your front-end Web server (nginx,\nApache, etc.) then you’d want to set this header there. On the other hand, if\nyou are using Django to do something like require authorization in order to\ndownload files and you cannot set the header using your Web server, this\nsetting will be useful.</p>\n</section>\n<section id=\"x-xss-protection-1-mode-block\">\n<span id=\"x-xss-protection\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">X-XSS-Protection:</span> <span class=\"pre\">1;</span> <span class=\"pre\">mode=block</span></code><a class=\"heading-anchor\" href=\"#x-xss-protection-1-mode-block\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Some browsers have the ability to block content that appears to be an <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Cross-site_scripting\">XSS\nattack</a>. They work by looking for JavaScript content in the GET or POST\nparameters of a page. If the JavaScript is replayed in the server’s response,\nthe page is blocked from rendering and an error page is shown instead.</p>\n<p>The <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection\">X-XSS-Protection header</a> is used to control the operation of the\nXSS filter.</p>\n<p>To enable the XSS filter in the browser, and force it to always block\nsuspected XSS attacks, you can pass the <code class=\"docutils literal notranslate\"><span class=\"pre\">X-XSS-Protection:</span> <span class=\"pre\">1;</span> <span class=\"pre\">mode=block</span></code>\nheader. <code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will do this for all responses if the\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_BROWSER_XSS_FILTER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_BROWSER_XSS_FILTER</span></code></a> setting is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Advertencia</p>\n<p>The browser XSS filter is a useful defense measure, but must not be\nrelied upon exclusively. It cannot detect all XSS attacks and not all\nbrowsers support the header. Ensure you are still <a class=\"reference internal\" href=\"/es/1.11/topics/security/#cross-site-scripting\"><span class=\"std std-ref\">validating and\nsanitizing</span></a> all input to prevent XSS attacks.</p>\n</aside>\n</section>\n<section id=\"ssl-redirect\">\n<span id=\"id4\"></span><h4>SSL Redirect<a class=\"heading-anchor\" href=\"#ssl-redirect\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>If your site offers both HTTP and HTTPS connections, most users will end up\nwith an unsecured connection by default. For best security, you should redirect\nall HTTP connections to HTTPS.</p>\n<p>If you set the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a> setting to True,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code> will permanently (HTTP 301) redirect all HTTP\nconnections to HTTPS.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>For performance reasons, it’s preferable to do these redirects outside of\nDjango, in a front-end load balancer or reverse-proxy server such as\n<a class=\"reference external\" href=\"http://nginx.org\">nginx</a>. <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_SSL_REDIRECT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_REDIRECT</span></code></a> is intended for the deployment\nsituations where this isn’t an option.</p>\n</aside>\n<p>If the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_SSL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_SSL_HOST</span></code></a> setting has a value, all redirects will be\nsent to that host instead of the originally-requested host.</p>\n<p>If there are a few pages on your site that should be available over HTTP, and\nnot redirected to HTTPS, you can list regular expressions to match those URLs\nin the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_REDIRECT_EXEMPT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_REDIRECT_EXEMPT</span></code></a> setting.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>If you are deployed behind a load-balancer or reverse-proxy server and\nDjango can’t seem to tell when a request actually is already secure, you\nmay need to set the <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-SECURE_PROXY_SSL_HEADER\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECURE_PROXY_SSL_HEADER</span></code></a> setting.</p>\n</aside>\n</section>\n</section>\n<section id=\"module-django.contrib.sessions.middleware\">\n<span id=\"session-middleware\"></span><h3>Session middleware<a class=\"heading-anchor\" href=\"#module-django.contrib.sessions.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.sessions.middleware.SessionMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">SessionMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.sessions.middleware.SessionMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Enables session support. See the <a class=\"reference internal\" href=\"/es/1.11/topics/http/sessions/\"><span class=\"doc\">session documentation</span></a>.</p>\n</section>\n<section id=\"module-django.contrib.sites.middleware\">\n<span id=\"site-middleware\"></span><h3>Site middleware<a class=\"heading-anchor\" href=\"#module-django.contrib.sites.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.sites.middleware.CurrentSiteMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">CurrentSiteMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.sites.middleware.CurrentSiteMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds the <code class=\"docutils literal notranslate\"><span class=\"pre\">site</span></code> attribute representing the current site to every incoming\n<code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> object. See the <a class=\"reference internal\" href=\"/es/1.11/ref/contrib/sites/#site-middleware\"><span class=\"std std-ref\">sites documentation</span></a>.</p>\n</section>\n<section id=\"module-django.contrib.auth.middleware\">\n<span id=\"authentication-middleware\"></span><h3>Authentication middleware<a class=\"heading-anchor\" href=\"#module-django.contrib.auth.middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.AuthenticationMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">AuthenticationMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.AuthenticationMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds the <code class=\"docutils literal notranslate\"><span class=\"pre\">user</span></code> attribute, representing the currently-logged-in user, to\nevery incoming <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> object. See <a class=\"reference internal\" href=\"/es/1.11/topics/auth/default/#auth-web-requests\"><span class=\"std std-ref\">Authentication in Web requests</span></a>.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.RemoteUserMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">RemoteUserMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.RemoteUserMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Middleware for utilizing Web server provided authentication. See\n<a class=\"reference internal\" href=\"/es/1.11/howto/auth-remote-user/\"><span class=\"doc\">Autenticación con el uso de REMOTE_USER</span></a> for usage details.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.auth.middleware.PersistentRemoteUserMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">PersistentRemoteUserMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.contrib.auth.middleware.PersistentRemoteUserMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Middleware for utilizing Web server provided authentication when enabled only\non the login page. See <a class=\"reference internal\" href=\"/es/1.11/howto/auth-remote-user/#persistent-remote-user-middleware-howto\"><span class=\"std std-ref\">Usando REMOTE_USER en paginas de ingreso solamente</span></a> for usage\ndetails.</p>\n</section>\n<section id=\"module-django.middleware.csrf\">\n<span id=\"csrf-protection-middleware\"></span><h3>CSRF protection middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.csrf\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.csrf.CsrfViewMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">CsrfViewMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.csrf.CsrfViewMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Adds protection against Cross Site Request Forgeries by adding hidden form\nfields to POST forms and checking requests for the correct value. See the\n<a class=\"reference internal\" href=\"/es/1.11/ref/csrf/\"><span class=\"doc\">Cross Site Request Forgery protection documentation</span></a>.</p>\n</section>\n<section id=\"module-django.middleware.clickjacking\">\n<span id=\"x-frame-options-middleware\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">X-Frame-Options</span></code> middleware<a class=\"heading-anchor\" href=\"#module-django.middleware.clickjacking\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.middleware.clickjacking.XFrameOptionsMiddleware\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">XFrameOptionsMiddleware</span></span><a class=\"heading-anchor\" href=\"#django.middleware.clickjacking.XFrameOptionsMiddleware\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Simple <a class=\"reference internal\" href=\"/es/1.11/ref/clickjacking/\"><span class=\"doc\">clickjacking protection via the X-Frame-Options header</span></a>.</p>\n</section>\n</section>\n<section id=\"middleware-ordering\">\n<span id=\"id5\"></span><h2>Middleware ordering<a class=\"heading-anchor\" href=\"#middleware-ordering\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Here are some hints about the ordering of various Django middleware classes:</p>\n<ol class=\"arabic\">\n<li><p><a class=\"reference internal\" href=\"#django.middleware.security.SecurityMiddleware\" title=\"django.middleware.security.SecurityMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SecurityMiddleware</span></code></a></p>\n<p>It should go near the top of the list if you’re going to turn on the SSL\nredirect as that avoids running through a bunch of other unnecessary\nmiddleware.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.cache.UpdateCacheMiddleware\" title=\"django.middleware.cache.UpdateCacheMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code></a></p>\n<p>Before those that modify the <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code> header (<code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code>,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">LocaleMiddleware</span></code>).</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.gzip.GZipMiddleware\" title=\"django.middleware.gzip.GZipMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code></a></p>\n<p>Before any middleware that may change or use the response body.</p>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code>: Modifies <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code> header.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.http.ConditionalGetMiddleware\" title=\"django.middleware.http.ConditionalGetMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ConditionalGetMiddleware</span></code></a></p>\n<p>Before <code class=\"docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code>: uses its <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> header when\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-USE_ETAGS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_ETAGS</span></code></a> = <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.contrib.sessions.middleware.SessionMiddleware\" title=\"django.contrib.sessions.middleware.SessionMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code></a></p>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code>: Modifies <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code> header.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.locale.LocaleMiddleware\" title=\"django.middleware.locale.LocaleMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">LocaleMiddleware</span></code></a></p>\n<p>One of the topmost, after <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code> (uses session data) and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">UpdateCacheMiddleware</span></code> (modifies <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code> header).</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.common.CommonMiddleware\" title=\"django.middleware.common.CommonMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CommonMiddleware</span></code></a></p>\n<p>Before any middleware that may change the response (it calculates <code class=\"docutils literal notranslate\"><span class=\"pre\">ETags</span></code>).</p>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">GZipMiddleware</span></code> so it won’t calculate an <code class=\"docutils literal notranslate\"><span class=\"pre\">ETag</span></code> header on gzipped\ncontents.</p>\n<p>Close to the top: it redirects when <a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> or\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-PREPEND_WWW\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">PREPEND_WWW</span></code></a> are set to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.csrf.CsrfViewMiddleware\" title=\"django.middleware.csrf.CsrfViewMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CsrfViewMiddleware</span></code></a></p>\n<p>Before any view middleware that assumes that CSRF attacks have been dealt\nwith.</p>\n<p>It must come after <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code> if you’re using\n<a class=\"reference internal\" href=\"/es/1.11/ref/settings/#std-setting-CSRF_USE_SESSIONS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_USE_SESSIONS</span></code></a>.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.contrib.auth.middleware.AuthenticationMiddleware\" title=\"django.contrib.auth.middleware.AuthenticationMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AuthenticationMiddleware</span></code></a></p>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code>: uses session storage.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.contrib.messages.middleware.MessageMiddleware\" title=\"django.contrib.messages.middleware.MessageMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">MessageMiddleware</span></code></a></p>\n<p>After <code class=\"docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code>: can use session-based storage.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"#django.middleware.cache.FetchFromCacheMiddleware\" title=\"django.middleware.cache.FetchFromCacheMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FetchFromCacheMiddleware</span></code></a></p>\n<p>After any middleware that modifies the <code class=\"docutils literal notranslate\"><span class=\"pre\">Vary</span></code> header: that header is used\nto pick a value for the cache hash-key.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/contrib/flatpages/#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware\" title=\"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FlatpageFallbackMiddleware</span></code></a></p>\n<p>Should be near the bottom as it’s a last-resort type of middleware.</p>\n</li>\n<li><p><a class=\"reference internal\" href=\"/es/1.11/ref/contrib/redirects/#django.contrib.redirects.middleware.RedirectFallbackMiddleware\" title=\"django.contrib.redirects.middleware.RedirectFallbackMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RedirectFallbackMiddleware</span></code></a></p>\n<p>Should be near the bottom as it’s a last-resort type of middleware.</p>\n</li>\n</ol>\n</section>","rootId":"module-django.middleware","toc":[{"title":"Available middleware","anchor":"available-middleware","children":[{"title":"Cache middleware","anchor":"module-django.middleware.cache","children":[]},{"title":"«Common» middleware","anchor":"module-django.middleware.common","children":[]},{"title":"GZip middleware","anchor":"module-django.middleware.gzip","children":[]},{"title":"Conditional GET middleware","anchor":"module-django.middleware.http","children":[]},{"title":"Locale middleware","anchor":"module-django.middleware.locale","children":[]},{"title":"Message middleware","anchor":"module-django.contrib.messages.middleware","children":[]},{"title":"Security middleware","anchor":"module-django.middleware.security","children":[{"title":"HTTP Strict Transport Security","anchor":"http-strict-transport-security","children":[]},{"title":"X-Content-Type-Options: nosniff","anchor":"x-content-type-options-nosniff","children":[]},{"title":"X-XSS-Protection: 1; mode=block","anchor":"x-xss-protection-1-mode-block","children":[]},{"title":"SSL Redirect","anchor":"ssl-redirect","children":[]}]},{"title":"Session middleware","anchor":"module-django.contrib.sessions.middleware","children":[]},{"title":"Site middleware","anchor":"module-django.contrib.sites.middleware","children":[]},{"title":"Authentication middleware","anchor":"module-django.contrib.auth.middleware","children":[]},{"title":"CSRF protection middleware","anchor":"module-django.middleware.csrf","children":[]},{"title":"X-Frame-Options middleware","anchor":"module-django.middleware.clickjacking","children":[]}]},{"title":"Middleware ordering","anchor":"middleware-ordering","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/es/1.11/ref/"}],"prev":{"docname":"ref/forms/validation","title":"Form and field validation","url":"/es/1.11/ref/forms/validation/"},"next":{"docname":"ref/migration-operations","title":"Migration Operations","url":"/es/1.11/ref/migration-operations/"},"formats":{"html":"/es/1.11/ref/middleware/","markdown":"/es/1.11/ref/middleware.md","json":"/es/1.11/ref/middleware.json"},"source":"https://github.com/django/django/blob/stable/1.11.x/docs/ref/middleware.txt","official":"https://docs.djangoproject.com/es/1.11/ref/middleware/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","fr","ja","id","pt-br","ko","es","el","pl"]}