How to use django-sitetree?

I am trying to use django-sitetree , but I do not understand how to do step 3, which:

"Go to the Django admin site and add trees and tree elements."

How to make sitetree in admin panel? I believe the first step is to choose an alias for the Site Tree that you are about to add.

The next step is to add the "Site Tree Element". On this page you must select the parent, title, URL. Given that my application is dynamic with a url structure, like this localhost:8000/categoryname/entryname , how do I select the urls?

By the way, I'm trying to add breadcrumbs to my templates.

+7
source share
1 answer

To create a tree:

  • Go to the site administration panel;
  • Click + Add next to the site trees;
  • Enter an alias for your sitetree, for example. 'Maintree.
    You will access your tree with this alias in the template tags;
  • Click "Add site tree element";
  • Create the first element:

    Parent:. Like the root element that did not have a parent.
    Title: Let it be "My Site".
    URL: This URL is static, so put '/' here.

  • Create a second element (which would handle "categoryname" from your "categoryname / entryname"):

    Parent: Select "My Site" from step 5.
    Title: Put here 'Category # {{category.id}}'.
    URL: Put the named URL 'category-detail category.name'.
    In the "Advanced Settings" section, select the " URL as template " checkbox.

  • Create the third element (which will handle the "login" from your "categoryname / entryname"):

    Parent: Select "Category # {{category.id}}" from step 6.
    Title: Put 'Entry # {{entry.id}}' here.
    URL: Put the named URL 'entry-detail category.name entry.name'.
    In the "Advanced Settings" section, select the " URL as template " checkbox.

  • Put '{% load sitetree%}' in the yor template to access the sitetree tags.
  • Put '{% sitetree_menu from "maintree"%}' in your template to display the menu.
  • Place '{% sitetree_breadcrumbs from "maintree"%}' in your template to display breadcrumbs.

Steps 6 and 7 need some explanation:

  • In the headers, we use Django template variables, which will be resolved in the same way as in your templates.

    For example: you made your presentation for "categoryname" (call it "detail_category") to pass the category object to the template as a category variable. Suppose a category object has an id property. In your template, you use '{{category.id}}' to render the id. And we are just the same for the site tree element in step 6.

  • In URLs, we use Django with URLs ( documentation ). This is almost identical to using the Django url 'tag in templates.

    Your URL configuration for steps 6, 7 should include:

    url (r '^ (? P <category_name> \ S +) / (? P <entry_name> \ S +) / $', 'detail_entry', name = ' verbose input ),
    url (r '^ (? P <category_name> \ S +) / $', 'detail_category', name = ' category-detail '),

    So, putting "entry-detail category.name entry.name" in step 7, we will specify sitetree to associate the sitetree element with a URL named "entry-detail", passing it the category_name and entry_name parameters.

I hope this description should fill the gap in the documentation%)

+18
source

All Articles