Getting started

  1. Add the sitetree application to INSTALLED_APPS in your settings file (usually ‘’).
  2. Check that django.core.context_processors.request is enabled in TEMPLATE_CONTEXT_PROCESSORS in your settings file.
  3. Check that django.contrib.auth.context_processors.auth is enabled in TEMPLATE_CONTEXT_PROCESSORS too.
  4. Run ‘./ syncdb’ to install sitetree tables into database.
  5. Go to Django Admin site and add some trees and tree items (see Making tree section).
  6. Add {% load sitetree %} tag to the top of a template.
Now you can use the following template tags:

Upgrade hint

When switching from older version of SiteTree to newer do not forget to upgrade your database schema.

That could be done with the following command issued in your Django project directory:

./ migrate

Note that the command requires South.

Making tree

Taken from StackOverflow.

In this tutoral we create sitetree that could handle URI like /categoryname/entryname.

To create a tree:

  1. Go to site administration panel;

  2. Click +Add near ‘Site Trees’;

  3. Enter alias for your sitetree, e.g. ‘maintree’. You’ll address your tree by this alias in template tags;

  4. Push ‘Add Site Tree Item’;

  5. Create first item:

    Parent - As it is root item that would have no parent.
    Title - Let it be 'My site'.
    URL - This URL is static, so put here '/'.
  6. Create second item (that one would handle ‘categoryname’ from your ‘categoryname/entryname’):

    Parent - Choose 'My site' item from step 5.
    Title - Put here 'Category #{{ }}'.
    URL - Put named URL 'category-detailed'.
    In 'Additional settings': check 'URL as Pattern' checkbox.
  7. Create third item (that one would handle ‘entryname’ from your ‘categoryname/entryname’):

    Parent - Choose 'Category #{{ }}' item from step 6.
    Title - Put here 'Entry #{{ }}'.
    URL - Put named URL 'entry-detailed'.
    In 'Additional settings': check 'URL as Pattern' checkbox.
  8. Put ‘{% load sitetree %}’ into yor template to have access to sitetree tags.

  9. Put ‘{% sitetree_menu from “maintree” %}’ into your template to render menu.

  10. Put ‘{% sitetree_breadcrumbs from “maintree” %}’ into your template to render breadcrumbs.

Steps 6 and 7 clarifications:

  • In titles we use Django template variables, which would be resolved just like they do in your templates.

    E.g.: You made your view for ‘categoryname’ (let’s call it ‘detailed_category’) to pass category object into template as ‘category’ variable. Suppose that category object has ‘id’ property. In your template you use ‘{{ }}’ to render id. And we do just the same for site tree item in step 6.

  • In URLs we use Django’s named URL patterns (documentation). That is almost idential to usage of Django ‘url‘ tag in templates.

    Your urls configuration for steps 6, 7 supposed to include:

    url(r'^(?P<category_name>\S+)/(?P<entry_name>\S+)/$', 'detailed_entry', name='entry-detailed'),
    url(r'^(?P<category_name>\S+)/$', 'detailed_category', name='category-detailed'),

    Consider ‘name’ argument values of ‘url’ function.

    So, putting ‘entry-detailed’ in step 7 into URL field we tell sitetree to associate that sitetree item with URL named ‘entry-detailed’, passing to it category_name and entry_name parameters.

Project Versions

Table Of Contents

Previous topic

django-sitetree documentation

Next topic

SiteTree template tags

This Page