Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > main-backports > by-pkgid > bc8a726fff5aedb19088c6244d3dd008 > files > 2815

python-django-1.2.4-1mdv2010.2.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 v1.2 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.2',
        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 v1.2 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="Databrowse" href="databrowse.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 v1.2 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="databrowse.html" title="Databrowse">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>
<div class="versionadded">
<span class="title">New in Django 1.0:</span> <a class="reference internal" href="../../releases/1.0.html"><em>Please, see the release notes</em></a></div>
<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>
<li><p class="first">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.</p>
</li>
<li><p class="first">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>.</p>
</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>
<p>The <tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt>
does all of the work. 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="xref py py-data docutils literal"><span class="pre">flatpage</span></tt>, which
is the flatpage object. It uses
<tt class="xref py py-class docutils literal"><span class="pre">RequestContext</span></tt> in rendering the
template.</li>
</ul>
<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>
<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 <tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt> at
the end of the list, because it&#8217;s a last resort.</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
<tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt>
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 (such as a <tt class="docutils literal"><span class="pre">TemplateDoesNotExist</span></tt>
exception if your site does not have an appropriate template to
use for HTTP 404 responses), the response will become an HTTP 500
(&#8220;Internal Server Error&#8221;) and the
<tt class="xref py py-class docutils literal"><span class="pre">FlatpageFallbackMiddleware</span></tt>
will not attempt to serve a flat page.</p>
</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="descclassname">models.</tt><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="http://code.djangoproject.com/browser/django/trunk/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>
</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="xref py py-data 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 PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;</span>
<span class="cp">    &quot;http://www.w3.org/TR/REC-html40/loose.dtd&quot;&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'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>


          </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></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>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="databrowse.html">Databrowse</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 v1.2 documentation</a>
        
          <ul><li><a href="../index.html">API Reference</a>
        
          <ul><li><a href="index.html"><tt class="docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal 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" size="18" />
      <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">Jan 28, 2011</p>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="databrowse.html" title="Databrowse">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>