<!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>) &mdash; django-page-cms v1.0.5 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.0.5',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="django-page-cms v1.0.5 documentation" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li><a href="index.html">django-page-cms v1.0.5 documentation</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <p>#summary Explain how to integrate django page cms into a legacy django project
#labels Featured</p>
<p>=Install in legacy project=</p>
<p>This document explain how to install django page CMS into an existing Django project. This document assume that you already know how to setup a Django project.</p>
<p>If you have any problem installing this CMS, take a look at the example application that stands in the example directory. This application works out of the box and will certainly help you to get started.</p>
<p>Pay a special attention to the following bold <em>must</em> statements.</p>
<p>=Install instructions step by step=</p>
<p>For an alternative, step by step installation process, there is this OpenOffice document : <a class="reference external" href="http://django-page-cms.googlegroups.com/web/gpc-install-instructions.odt">http://django-page-cms.googlegroups.com/web/gpc-install-instructions.odt</a></p>
<p>==Install by using pip==</p>
<p>The pip install is by far the easiest one. Use this method if you have the choice.</p>
<p>use :</p>
<p>{{{
sudo easy_install pip
wget -c <a class="reference external" href="http://django-page-cms.googlecode.com/svn/trunk/requirements/external_apps.txt">http://django-page-cms.googlecode.com/svn/trunk/requirements/external_apps.txt</a>
sudo pip install -r external_apps.txt
}}}</p>
<p>Every package listed in the <cite>external_app.txt</cite> should be downloaded and installed.</p>
<p>==Install by using easy_install==</p>
<p>On debian linux you can do:</p>
<p>{{{
sudo easy_install html5lib
sudo easy_install django-page-cms
}}}</p>
<p><em>Tagging must be installed by hand or with subversion</em> because the available package is not
compatible with django 1.0.</p>
<p><em>Django-mptt must be installed by hand or with subversion</em> because the available package is not compatible with django 1.0.</p>
<p>==Install by using subversion externals==</p>
<p>You can also use the trunk version of the Django page CMS by using subversion externals</p>
<p>{{{
$ svn pe svn:externals .
pages                   http://django-page-cms.googlecode.com/svn/trunk/pages
mptt                    http://django-mptt.googlecode.com/svn/trunk/mptt
tagging                 http://django-tagging.googlecode.com/svn/trunk/tagging
}}}</p>
<p>==Urls==</p>
<p>Take a look in the <cite>example/urls.py</cite> and copy desired URLs in your own <cite>urls.py</cite>. Basically you need to have something like this:</p>
<p>{{{
urlpatterns = patterns(&#8216;&#8217;,</p>
<blockquote>
...
url(r&#8217;^pages/&#8217;, include(&#8216;pages.urls&#8217;)),
(r&#8217;^admin/(.*)&#8217;, admin.site.root),</blockquote>
<div class="section" id="id1">
<h1>)<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1>
<p>When you will visit the site the first time (<cite>/pages/</cite>), you will get a 404 error because there is no published page. Go to the admin first and create and publish some pages.</p>
<p>You will certainly want to activate the static file serve view in your <cite>urls.py</cite> if you are in developement mode:</p>
<p>{{{
if settings.DEBUG:</p>
<blockquote>
<dl class="docutils">
<dt>urlpatterns += patterns(&#8216;&#8217;,</dt>
<dd># Trick for Django to support static files (security hole: only for Dev environement! remove this on Prod!!!)
url(r&#8217;^media/(?P&lt;path&gt;.*)$&#8217;, &#8216;django.views.static.serve&#8217;, {&#8216;document_root&#8217;: settings.MEDIA_ROOT}),
url(r&#8217;^admin_media/(?P&lt;path&gt;.*)$&#8217;, &#8216;django.views.static.serve&#8217;, {&#8216;document_root&#8217;: settings.ADMIN_MEDIA_ROOT}),</dd>
</dl>
<p>)</p>
</blockquote>
<p>}}}</p>
<p>==Settings==</p>
<p>All the Django page CMS specific settings and options are listed and explained in the <cite>pages/settings.py</cite> file.</p>
<p>Django page CMS require several of these settings to be set. They are marked in this document with a bold &#8220;<em>must</em>&#8220;.</p>
<p>===Tagging===</p>
<p>Tagging is optional and disabled by default.</p>
<p>If you want to use it set <cite>PAGE_TAGGING</cite> at <cite>True</cite> into your setting file and add it to your installed apps :</p>
<p>{{{
INSTALLED_APPS = (</p>
<blockquote>
&#8216;django.contrib.auth&#8217;,
&#8216;django.contrib.contenttypes&#8217;,
&#8216;django.contrib.sessions&#8217;,
&#8216;django.contrib.admin&#8217;,
&#8216;django.contrib.sites&#8217;,
&#8216;mptt&#8217;,
&#8216;tagging&#8217;,
&#8216;pages&#8217;,
...</blockquote>
</div>
<div class="section" id="id2">
<h1>)<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h1>
<p>===Caching===</p>
<p>Django page CMS use the caching framework quite intensively. You should definitely set-up [<a class="reference external" href="http://docs.djangoproject.com/en/dev/topics/cache/#setting-up-the-cache">http://docs.djangoproject.com/en/dev/topics/cache/#setting-up-the-cache</a> use one of the caching backend] to have decent performance.</p>
<p>If you cannot setup memcache or a database cache, you can use the local memory cache this way:</p>
<p>{{{
CACHE_BACKEND = &#8220;locmem:///?max_entries=5000&#8221;
}}}</p>
<p>===Languages===</p>
<p>Please first read how django handle languages:</p>
<blockquote>
<ul class="simple">
<li><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#languages">http://docs.djangoproject.com/en/dev/ref/settings/#languages</a></li>
<li><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/settings/#language-code">http://docs.djangoproject.com/en/dev/ref/settings/#language-code</a></li>
</ul>
</blockquote>
<p>This CMS use the <cite>PAGE_LANGUAGES</cite> setting in order to present which language are supported by the CMS.</p>
<p>By default <cite>PAGE_LANGUAGES</cite> value is set by <cite>settings.LANGUAGES</cite> so you can directly set the <cite>LANGUAGES</cite> setting if you want.</p>
<p>In any case <em>you should set</em> <cite>PAGE_LANGUAGES</cite> or <cite>LANGUAGES</cite> yourself because by default the <cite>LANGUAGES</cite> list is big.</p>
<p>Django use <cite>LANGUAGES</cite> setting to set the <cite>request.LANGUAGE_CODE</cite> value that is used by this CMS. So if the language you want to support is not present in the <cite>LANGUAGES</cite> setting the <cite>request.LANGUAGE_CODE</cite> will not be set correctly.</p>
<p>A possible solution is to redefine <cite>settings.LANGUAGES</cite>. For example you can do :</p>
<p>{{{
# Default language code for this installation. All choices can be found here:
# <a class="reference external" href="http://www.i18nguy.com/unicode/language-identifiers.html">http://www.i18nguy.com/unicode/language-identifiers.html</a>
LANGUAGE_CODE = &#8216;en-us&#8217;</p>
<p># This is defined here as a do-nothing function because we can&#8217;t import
# django.utils.translation &#8211; that module depends on the settings.
gettext_noop = lambda s: s</p>
<p># here is all the languages you want to be supported by the CMS
PAGE_LANGUAGES = (</p>
<blockquote>
(&#8216;de&#8217;, gettext_noop(&#8216;German&#8217;)),
(&#8216;fr-ch&#8217;, gettext_noop(&#8216;Swiss french&#8217;)),
(&#8216;en-us&#8217;, gettext_noop(&#8216;US English&#8217;)),</blockquote>
<p>)</p>
<p># You should add here all language you want to accept as valid client language
languages = list(PAGE_LANGUAGES)
languages.append((&#8216;fr-fr&#8217;, gettext_noop(&#8216;French&#8217;)))
languages.append((&#8216;fr-be&#8217;, gettext_noop(&#8216;Belgium french&#8217;)))
# redefine the LANGUAGES setting in order to set request.LANGUAGE_CODE correctly
LANGUAGES = languages</p>
<p># This enable you to map a language(s) to another one, these languages should
# be in the LANGUAGES config
def language_mapping(lang):</p>
<blockquote>
<dl class="docutils">
<dt>if lang.startswith(&#8216;fr&#8217;):</dt>
<dd># serve swiss french for everyone
return &#8216;fr-ch&#8217;</dd>
</dl>
<p>return lang</p>
</blockquote>
<p>PAGE_LANGUAGE_MAPPING = language_mapping
}}}</p>
<p>===Template context processors and Middlewares===</p>
<p>You <em>must</em> have these context processors into your <cite>TEMPLATE_CONTEXT_PROCESSORS</cite> setting:</p>
<p>{{{
TEMPLATE_CONTEXT_PROCESSORS = (</p>
<blockquote>
...
&#8220;django.core.context_processors.auth&#8221;,
&#8220;django.core.context_processors.i18n&#8221;,
&#8220;django.core.context_processors.debug&#8221;,
&#8220;django.core.context_processors.media&#8221;,
&#8220;django.core.context_processors.request&#8221;,
&#8220;pages.context_processors.media&#8221;,
...</blockquote>
</div>
<div class="section" id="id3">
<h1>)<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h1>
<p>You <em>must</em> have these middleware into your <cite>MIDDLEWARE_CLASSES</cite> setting:</p>
<p>{{{
MIDDLEWARE_CLASSES = (</p>
<blockquote>
&#8216;django.contrib.sessions.middleware.SessionMiddleware&#8217;,
&#8216;django.middleware.common.CommonMiddleware&#8217;,
&#8216;django.contrib.auth.middleware.AuthenticationMiddleware&#8217;,
&#8216;django.middleware.doc.XViewMiddleware&#8217;,
&#8216;django.middleware.locale.LocaleMiddleware&#8217;,
...</blockquote>
</div>
<div class="section" id="id4">
<h1>)<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h1>
<p>===Default template===</p>
<p>You <em>must</em> set <cite>DEFAULT_PAGE_TEMPLATE</cite> to the name of your default CMS template.</p>
<p>{{{
DEFAULT_PAGE_TEMPLATE = &#8216;pages/index.html&#8217;
}}}</p>
<p>And you <em>must</em> copy the directory <cite>example/templates/pages</cite> into your root template directory.</p>
<p>===Additional templates===</p>
<p>Optionally you can set <cite>PAGE_TEMPLATES</cite> if you want additional templates choices. In the the example application you have actually this:</p>
<p>{{{
PAGE_TEMPLATES = (</p>
<blockquote>
(&#8216;pages/nice.html&#8217;, &#8216;nice one&#8217;),
(&#8216;pages/cool.html&#8217;, &#8216;cool one&#8217;),</blockquote>
</div>
<div class="section" id="id5">
<h1>)<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h1>
<p>===The sites framework===</p>
<p>If you want to use the [<a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/contrib/sites/#ref-contrib-sites">http://docs.djangoproject.com/en/dev/ref/contrib/sites/#ref-contrib-sites</a> Django sites framework] with django-page-cms, you <em>must</em> define the <cite>SITE_ID</cite> and <cite>PAGE_USE_SITE_ID</cite> settings and create the appropriate Site object into the admin interface.</p>
<p>{{{
PAGE_USE_SITE_ID = True
SITE_ID = 1
}}}</p>
<p>The Site object should have the domain that match your actual domain (ie: 127.0.0.1:8000)</p>
<p>===Media directory===</p>
<p>The django CMS come with some javascript and CSS files. These files are standing in the <cite>pages/media/pages</cite> directory.</p>
<p>If you don&#8217;t know how to serve static files with Django please read :</p>
<p><a class="reference external" href="http://docs.djangoproject.com/en/dev/howto/static-files/">http://docs.djangoproject.com/en/dev/howto/static-files/</a></p>
<p>Django CMS has a special setting called <cite>PAGES_MEDIA_URL</cite> that enable you to change how the browser will ask for these files in the CMS admin. By default the value of <cite>PAGES_MEDIA_URL</cite> is set to :</p>
<p>{{{
PAGES_MEDIA_URL = getattr(settings, &#8216;PAGES_MEDIA_URL&#8217;, join(settings.MEDIA_URL, &#8216;pages/&#8217;))
}}}</p>
<p>Or in a simpler way :</p>
<p>{{{
PAGES_MEDIA_URL = settings.MEDIA_URL + &#8220;pages/&#8221;
}}}</p>
<p>In the CMS admin template you have</p>
<p>{{{
&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;{{ PAGES_MEDIA_URL }}css/pages.css&#8221; /&gt;
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;{{ PAGES_MEDIA_URL }}javascript/jquery.js&#8221;&gt;&lt;/script&gt;
}}}</p>
<p>That will be rendered by default like this if <cite>MEDIA_URL == &#8216;/media/&#8217;</cite></p>
<p>{{{
&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;/media/pages/css/pages.css&#8221; /&gt;
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;/media/pages/javascript/jquery.js&#8221;&gt;&lt;/script&gt;
}}}</p>
<p>You can off course redefine this variable in your setting file if you are not happy with this default.</p>
<p><em>You must at least create a symbolic link or copy the directory `pages/media/pages/`</em> into your media directory to have a fully functioning administration interface.</p>
<p>The example application take another approch by directly point the <cite>MEDIA_ROOT</cite> of the project on the <cite>page/media</cite> directory :</p>
<p>{{{
# Absolute path to the directory that holds media.
MEDIA_ROOT = os.path.join(PROJECT_DIR, &#8216;../pages/media/&#8217;)
ADMIN_MEDIA_ROOT = os.path.join(PROJECT_DIR, &#8216;../admin_media/&#8217;)
MEDIA_URL = &#8216;/media/&#8217;
ADMIN_MEDIA_PREFIX = &#8216;/admin_media/&#8217;
}}}</p>
<p>But you certainly want to redefine these variables to your own project media directory.</p>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">)</a></li>
<li><a class="reference external" href="#id2">)</a></li>
<li><a class="reference external" href="#id3">)</a></li>
<li><a class="reference external" href="#id4">)</a></li>
<li><a class="reference external" href="#id5">)</a></li>
</ul>

            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/InstallDjangoPageCMS.txt">Show Source</a></li>
            </ul>
          <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>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li><a href="index.html">django-page-cms v1.0.5 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Batiste Bieler.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.5.2.
    </div>
  </body>
</html>