Sophie

Sophie

distrib > Fedora > 20 > i386 > by-pkgid > 422242acff54b9373d7d4b7f73232ce1 > files > 596

python3-django-doc-1.6.7-1.fc20.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">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The flatpages app &mdash; Django 1.6.7 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.6.7',
        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="top" title="Django 1.6.7 documentation" href="../../index.html" />
    <link rel="up" title="contrib packages" href="index.html" />
    <link rel="next" title="django.contrib.formtools" href="formtools/index.html" />
    <link rel="prev" title="Cross Site Request Forgery protection" href="csrf.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 = "../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>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.6.7 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="csrf.html" title="Cross Site Request Forgery protection">previous</a> 
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="formtools/index.html" title="django.contrib.formtools">next</a> &raquo;</div>
    </div>
    
    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-flatpages">
            
  <div class="section" id="s-module-django.contrib.flatpages">
<span id="s-the-flatpages-app"></span><span id="module-django.contrib.flatpages"></span><span id="the-flatpages-app"></span><h1>The flatpages app<a class="headerlink" href="#module-django.contrib.flatpages" title="Permalink to this headline">¶</a></h1>
<p>Django comes with an optional &#8220;flatpages&#8221; application. It lets you store simple
&#8220;flat&#8221; HTML content in a database and handles the management for you via
Django&#8217;s admin interface and a Python API.</p>
<p>A flatpage is a simple object with a URL, title and content. Use it for
one-off, special-case pages, such as &#8220;About&#8221; or &#8220;Privacy Policy&#8221; pages, that
you want to store in a database but for which you don&#8217;t want to develop a
custom Django application.</p>
<p>A flatpage can use a custom template or a default, systemwide flatpage
template. It can be associated with one, or multiple, sites.</p>
<p>The content field may optionally be left blank if you prefer to put your
content in a custom template.</p>
<p>Here are some examples of flatpages on Django-powered sites:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.lawrence.com/about/contact/">http://www.lawrence.com/about/contact/</a></li>
<li><a class="reference external" href="http://www2.ljworld.com/site/rules/">http://www2.ljworld.com/site/rules/</a></li>
</ul>
<div class="section" id="s-installation">
<span id="installation"></span><h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<p>To install the flatpages app, follow these steps:</p>
<ol class="arabic">
<li><p class="first">Install the <a class="reference internal" href="sites.html#module-django.contrib.sites" title="django.contrib.sites: Lets you operate multiple Web sites from the same database and Django project"><tt class="xref py py-mod docutils literal"><span class="pre">sites</span> <span class="pre">framework</span></tt></a> by adding
<tt class="docutils literal"><span class="pre">'django.contrib.sites'</span></tt> to your <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> setting,
if it&#8217;s not already in there.</p>
<p>Also make sure you&#8217;ve correctly set <a class="reference internal" href="../settings.html#std:setting-SITE_ID"><tt class="xref std std-setting docutils literal"><span class="pre">SITE_ID</span></tt></a> to the ID of the
site the settings file represents. This will usually be <tt class="docutils literal"><span class="pre">1</span></tt> (i.e.
<tt class="docutils literal"><span class="pre">SITE_ID</span> <span class="pre">=</span> <span class="pre">1</span></tt>, but if you&#8217;re using the sites framework to manage
multiple sites, it could be the ID of a different site.</p>
</li>
<li><p class="first">Add <tt class="docutils literal"><span class="pre">'django.contrib.flatpages'</span></tt> to your <a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a>
setting.</p>
</li>
</ol>
<p>Then either:</p>
<ol class="arabic" start="3">
<li><p class="first">Add an entry in your URLconf. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^pages/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s">&#39;django.contrib.flatpages.urls&#39;</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
</li>
</ol>
<p>or:</p>
<ol class="arabic simple" start="3">
<li>Add <tt class="docutils literal"><span class="pre">'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'</span></tt>
to your <a class="reference internal" href="../settings.html#std:setting-MIDDLEWARE_CLASSES"><tt class="xref std std-setting docutils literal"><span class="pre">MIDDLEWARE_CLASSES</span></tt></a> setting.</li>
<li>Run the command <a class="reference internal" href="../django-admin.html#django-admin-syncdb"><tt class="xref std std-djadmin docutils literal"><span class="pre">manage.py</span> <span class="pre">syncdb</span></tt></a>.</li>
</ol>
</div>
<div class="section" id="s-how-it-works">
<span id="how-it-works"></span><h2>How it works<a class="headerlink" href="#how-it-works" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">manage.py</span> <span class="pre">syncdb</span></tt> creates two tables in your database: <tt class="docutils literal"><span class="pre">django_flatpage</span></tt>
and <tt class="docutils literal"><span class="pre">django_flatpage_sites</span></tt>. <tt class="docutils literal"><span class="pre">django_flatpage</span></tt> is a simple lookup table
that simply maps a URL to a title and bunch of text content.
<tt class="docutils literal"><span class="pre">django_flatpage_sites</span></tt> associates a flatpage with a site.</p>
<div class="section" id="s-using-the-urlconf">
<span id="using-the-urlconf"></span><h3>Using the URLconf<a class="headerlink" href="#using-the-urlconf" title="Permalink to this headline">¶</a></h3>
<p>There are several ways to include the flat pages in your URLconf. You can
dedicate a particular path to flat pages:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^pages/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s">&#39;django.contrib.flatpages.urls&#39;</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>You can also set it up as a &#8220;catchall&#8221; pattern. In this case, it is important
to place the pattern at the end of the other urlpatterns:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># Your other patterns here</span>
<span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;django.contrib.flatpages.views&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^(?P&lt;url&gt;.*/)$&#39;</span><span class="p">,</span> <span class="s">&#39;flatpage&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">If you set <a class="reference internal" href="../settings.html#std:setting-APPEND_SLASH"><tt class="xref std std-setting docutils literal"><span class="pre">APPEND_SLASH</span></tt></a> to <tt class="docutils literal"><span class="pre">False</span></tt>, you must remove the slash
in the catchall pattern or flatpages without a trailing slash will not be
matched.</p>
</div>
<p>Another common setup is to use flat pages for a limited set of known pages and
to hard code the urls, so you can reference them with the <a class="reference internal" href="../templates/builtins.html#std:templatetag-url"><tt class="xref std std-ttag docutils literal"><span class="pre">url</span></tt></a> template
tag:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;django.contrib.flatpages.views&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^about-us/$&#39;</span><span class="p">,</span> <span class="s">&#39;flatpage&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;url&#39;</span><span class="p">:</span> <span class="s">&#39;/about-us/&#39;</span><span class="p">},</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;about&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^license/$&#39;</span><span class="p">,</span> <span class="s">&#39;flatpage&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;url&#39;</span><span class="p">:</span> <span class="s">&#39;/license/&#39;</span><span class="p">},</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;license&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-using-the-middleware">
<span id="using-the-middleware"></span><h3>Using the middleware<a class="headerlink" href="#using-the-middleware" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference internal" href="#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware" title="django.contrib.flatpages.middleware.FlatpageFallbackMiddleware"><tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt></a>
can do all of the work.</p>
<dl class="class">
<dt id="django.contrib.flatpages.middleware.FlatpageFallbackMiddleware">
<em class="property">class </em><tt class="descname">FlatpageFallbackMiddleware</tt><a class="headerlink" href="#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware" title="Permalink to this definition">¶</a></dt>
<dd><p>Each time any Django application raises a 404 error, this middleware
checks the flatpages database for the requested URL as a last resort.
Specifically, it checks for a flatpage with the given URL with a site ID
that corresponds to the <a class="reference internal" href="../settings.html#std:setting-SITE_ID"><tt class="xref std std-setting docutils literal"><span class="pre">SITE_ID</span></tt></a> setting.</p>
<p>If it finds a match, it follows this algorithm:</p>
<ul class="simple">
<li>If the flatpage has a custom template, it loads that template.
Otherwise, it loads the template <tt class="file docutils literal"><span class="pre">flatpages/default.html</span></tt>.</li>
<li>It passes that template a single context variable, <tt class="docutils literal"><span class="pre">flatpage</span></tt>,
which is the flatpage object. It uses
<a class="reference internal" href="../templates/api.html#django.template.RequestContext" title="django.template.RequestContext"><tt class="xref py py-class docutils literal"><span class="pre">RequestContext</span></tt></a> in rendering the
template.</li>
</ul>
<p>The middleware will only add a trailing slash and redirect (by looking
at the <a class="reference internal" href="../settings.html#std:setting-APPEND_SLASH"><tt class="xref std std-setting docutils literal"><span class="pre">APPEND_SLASH</span></tt></a> setting) if the resulting URL refers to
a valid flatpage. Redirects are permanent (301 status code).</p>
<p>If it doesn&#8217;t find a match, the request continues to be processed as usual.</p>
<p>The middleware only gets activated for 404s &#8211; not for 500s or responses
of any other status code.</p>
</dd></dl>

<div class="admonition-flatpages-will-not-apply-view-middleware admonition">
<p class="first admonition-title">Flatpages will not apply view middleware</p>
<p class="last">Because the <tt class="docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt> is applied only after
URL resolution has failed and produced a 404, the response it
returns will not apply any <a class="reference internal" href="../../topics/http/middleware.html#view-middleware"><em>view middleware</em></a>
methods. Only requests which are successfully routed to a view via
normal URL resolution apply view middleware.</p>
</div>
<p>Note that the order of <a class="reference internal" href="../settings.html#std:setting-MIDDLEWARE_CLASSES"><tt class="xref std std-setting docutils literal"><span class="pre">MIDDLEWARE_CLASSES</span></tt></a> matters. Generally, you
can put
<a class="reference internal" href="#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware" title="django.contrib.flatpages.middleware.FlatpageFallbackMiddleware"><tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt></a> at the
end of the list. This means it will run first when processing the response, and
ensures that any other response-processing middlewares see the real flatpage
response rather than the 404.</p>
<p>For more on middleware, read the <a class="reference internal" href="../../topics/http/middleware.html"><em>middleware docs</em></a>.</p>
<div class="admonition-ensure-that-your-404-template-works admonition">
<p class="first admonition-title">Ensure that your 404 template works</p>
<p class="last">Note that the
<a class="reference internal" href="#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware" title="django.contrib.flatpages.middleware.FlatpageFallbackMiddleware"><tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt></a>
only steps in once another view has successfully produced a 404 response.
If another view or middleware class attempts to produce a 404 but ends up
raising an exception instead, the response will become an HTTP 500
(&#8220;Internal Server Error&#8221;) and the
<a class="reference internal" href="#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware" title="django.contrib.flatpages.middleware.FlatpageFallbackMiddleware"><tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt></a>
will not attempt to serve a flat page.</p>
</div>
</div>
</div>
<div class="section" id="s-how-to-add-change-and-delete-flatpages">
<span id="how-to-add-change-and-delete-flatpages"></span><h2>How to add, change and delete flatpages<a class="headerlink" href="#how-to-add-change-and-delete-flatpages" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-via-the-admin-interface">
<span id="via-the-admin-interface"></span><h3>Via the admin interface<a class="headerlink" href="#via-the-admin-interface" title="Permalink to this headline">¶</a></h3>
<p>If you&#8217;ve activated the automatic Django admin interface, you should see a
&#8220;Flatpages&#8221; section on the admin index page. Edit flatpages as you edit any
other object in the system.</p>
</div>
<div class="section" id="s-via-the-python-api">
<span id="via-the-python-api"></span><h3>Via the Python API<a class="headerlink" href="#via-the-python-api" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.contrib.flatpages.models.FlatPage">
<em class="property">class </em><tt class="descname">FlatPage</tt><a class="headerlink" href="#django.contrib.flatpages.models.FlatPage" title="Permalink to this definition">¶</a></dt>
<dd><p>Flatpages are represented by a standard
<a class="reference internal" href="../../topics/db/models.html"><em>Django model</em></a>,
which lives in <a class="reference external" href="https://github.com/django/django/blob/master/django/contrib/flatpages/models.py">django/contrib/flatpages/models.py</a>. You can access
flatpage objects via the <a class="reference internal" href="../../topics/db/queries.html"><em>Django database API</em></a>.</p>
</dd></dl>

<div class="admonition-check-for-duplicate-flatpage-urls admonition">
<p class="first admonition-title">Check for duplicate flatpage URLs.</p>
<p class="last">If you add or modify flatpages via your own code, you will likely want to
check for duplicate flatpage URLs within the same site. The flatpage form
used in the admin performs this validation check, and can be imported from
<tt class="docutils literal"><span class="pre">django.contrib.flatpages.forms.FlatPageForm</span></tt> and used in your own
views.</p>
</div>
</div>
</div>
<div class="section" id="s-flatpage-templates">
<span id="flatpage-templates"></span><h2>Flatpage templates<a class="headerlink" href="#flatpage-templates" title="Permalink to this headline">¶</a></h2>
<p>By default, flatpages are rendered via the template
<tt class="file docutils literal"><span class="pre">flatpages/default.html</span></tt>, but you can override that for a
particular flatpage: in the admin, a collapsed fieldset titled
&#8220;Advanced options&#8221; (clicking will expand it) contains a field for
specifying a template name. If you&#8217;re creating a flat page via the
Python API you can simply set the template name as the field
<tt class="docutils literal"><span class="pre">template_name</span></tt> on the <tt class="docutils literal"><span class="pre">FlatPage</span></tt> object.</p>
<p>Creating the <tt class="file docutils literal"><span class="pre">flatpages/default.html</span></tt> template is your responsibility;
in your template directory, just create a <tt class="file docutils literal"><span class="pre">flatpages</span></tt> directory
containing a file <tt class="file docutils literal"><span class="pre">default.html</span></tt>.</p>
<p>Flatpage templates are passed a single context variable, <tt class="docutils literal"><span class="pre">flatpage</span></tt>,
which is the flatpage object.</p>
<p>Here&#8217;s a sample <tt class="file docutils literal"><span class="pre">flatpages/default.html</span></tt> template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">&lt;!DOCTYPE html&gt;</span>
<span class="nt">&lt;html&gt;</span>
<span class="nt">&lt;head&gt;</span>
<span class="nt">&lt;title&gt;</span><span class="cp">{{</span> <span class="nv">flatpage.title</span> <span class="cp">}}</span><span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;/head&gt;</span>
<span class="nt">&lt;body&gt;</span>
<span class="cp">{{</span> <span class="nv">flatpage.content</span> <span class="cp">}}</span>
<span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</pre></div>
</div>
<p>Since you&#8217;re already entering raw HTML into the admin page for a flatpage,
both <tt class="docutils literal"><span class="pre">flatpage.title</span></tt> and <tt class="docutils literal"><span class="pre">flatpage.content</span></tt> are marked as <strong>not</strong>
requiring <a class="reference internal" href="../../topics/templates.html#automatic-html-escaping"><em>automatic HTML escaping</em></a> in the
template.</p>
</div>
<div class="section" id="s-getting-a-list-of-flatpage-objects-in-your-templates">
<span id="getting-a-list-of-flatpage-objects-in-your-templates"></span><h2>Getting a list of <a class="reference internal" href="#django.contrib.flatpages.models.FlatPage" title="django.contrib.flatpages.models.FlatPage"><tt class="xref py py-class docutils literal"><span class="pre">FlatPage</span></tt></a> objects in your templates<a class="headerlink" href="#getting-a-list-of-flatpage-objects-in-your-templates" title="Permalink to this headline">¶</a></h2>
<p>The flatpages app provides a template tag that allows you to iterate
over all of the available flatpages on the <a class="reference internal" href="sites.html#hooking-into-current-site-from-views"><em>current site</em></a>.</p>
<p>Like all custom template tags, you&#8217;ll need to <a class="reference internal" href="../../topics/templates.html#loading-custom-template-libraries"><em>load its custom
tag library</em></a> before you can use
it. After loading the library, you can retrieve all current flatpages
via the <a class="reference internal" href="#std:templatetag-get_flatpages"><tt class="xref std std-ttag docutils literal"><span class="pre">get_flatpages</span></tt></a> tag:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">flatpages</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">get_flatpages</span> <span class="k">as</span> <span class="nv">flatpages</span> <span class="cp">%}</span>
<span class="nt">&lt;ul&gt;</span>
    <span class="cp">{%</span> <span class="k">for</span> <span class="nv">page</span> <span class="k">in</span> <span class="nv">flatpages</span> <span class="cp">%}</span>
        <span class="nt">&lt;li&gt;&lt;a</span> <span class="na">href=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">page.url</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="nt">&gt;</span><span class="cp">{{</span> <span class="nv">page.title</span> <span class="cp">}}</span><span class="nt">&lt;/a&gt;&lt;/li&gt;</span>
    <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="nt">&lt;/ul&gt;</span>
</pre></div>
</div>
<div class="section" id="s-displaying-registration-required-flatpages">
<span id="s-std:templatetag-get_flatpages"></span><span id="displaying-registration-required-flatpages"></span><span id="std:templatetag-get_flatpages"></span><h3>Displaying <tt class="docutils literal"><span class="pre">registration_required</span></tt> flatpages<a class="headerlink" href="#displaying-registration-required-flatpages" title="Permalink to this headline">¶</a></h3>
<p>By default, the <a class="reference internal" href="#std:templatetag-get_flatpages"><tt class="xref std std-ttag docutils literal"><span class="pre">get_flatpages</span></tt></a> templatetag will only show
flatpages that are marked <tt class="docutils literal"><span class="pre">registration_required</span> <span class="pre">=</span> <span class="pre">False</span></tt>. If you
want to display registration-protected flatpages, you need to specify
an authenticated user using a <tt class="docutils literal"><span class="pre">for</span></tt> clause.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">get_flatpages</span> <span class="nv">for</span> <span class="nv">someuser</span> <span class="k">as</span> <span class="nv">about_pages</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>If you provide an anonymous user, <a class="reference internal" href="#std:templatetag-get_flatpages"><tt class="xref std std-ttag docutils literal"><span class="pre">get_flatpages</span></tt></a> will behave
the same as if you hadn&#8217;t provided a user &#8211; i.e., it will only show you
public flatpages.</p>
</div>
<div class="section" id="s-limiting-flatpages-by-base-url">
<span id="limiting-flatpages-by-base-url"></span><h3>Limiting flatpages by base URL<a class="headerlink" href="#limiting-flatpages-by-base-url" title="Permalink to this headline">¶</a></h3>
<p>An optional argument, <tt class="docutils literal"><span class="pre">starts_with</span></tt>, can be applied to limit the
returned pages to those beginning with a particular base URL. This
argument may be passed as a string, or as a variable to be resolved
from the context.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">get_flatpages</span> <span class="s1">&#39;/about/&#39;</span> <span class="k">as</span> <span class="nv">about_pages</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">get_flatpages</span> <span class="nv">about_prefix</span> <span class="k">as</span> <span class="nv">about_pages</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">get_flatpages</span> <span class="s1">&#39;/about/&#39;</span> <span class="nv">for</span> <span class="nv">someuser</span> <span class="k">as</span> <span class="nv">about_pages</span> <span class="cp">%}</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>         
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The flatpages app</a><ul>
<li><a class="reference internal" href="#installation">Installation</a></li>
<li><a class="reference internal" href="#how-it-works">How it works</a><ul>
<li><a class="reference internal" href="#using-the-urlconf">Using the URLconf</a></li>
<li><a class="reference internal" href="#using-the-middleware">Using the middleware</a></li>
</ul>
</li>
<li><a class="reference internal" href="#how-to-add-change-and-delete-flatpages">How to add, change and delete flatpages</a><ul>
<li><a class="reference internal" href="#via-the-admin-interface">Via the admin interface</a></li>
<li><a class="reference internal" href="#via-the-python-api">Via the Python API</a></li>
</ul>
</li>
<li><a class="reference internal" href="#flatpage-templates">Flatpage templates</a></li>
<li><a class="reference internal" href="#getting-a-list-of-flatpage-objects-in-your-templates">Getting a list of <tt class="docutils literal"><span class="pre">FlatPage</span></tt> objects in your templates</a><ul>
<li><a class="reference internal" href="#displaying-registration-required-flatpages">Displaying <tt class="docutils literal"><span class="pre">registration_required</span></tt> flatpages</a></li>
<li><a class="reference internal" href="#limiting-flatpages-by-base-url">Limiting flatpages by base URL</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="csrf.html">Cross Site Request Forgery protection</a></li>
    
    
      <li>Next: <a href="formtools/index.html">django.contrib.formtools</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../index.html">Django 1.6.7 documentation</a>
        
          <ul><li><a href="../index.html">API Reference</a>
        
          <ul><li><a href="index.html"><tt class="docutils literal"><span class="pre">contrib</span></tt> packages</a>
        
        <ul><li>The flatpages app</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>  

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/ref/contrib/flatpages.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Sep 26, 2014</p>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="csrf.html" title="Cross Site Request Forgery protection">previous</a> 
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="formtools/index.html" title="django.contrib.formtools">next</a> &raquo;</div>
    </div>
  </div>

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