如何使用django-sitetree? [英] How to use django-sitetree?

查看:262
本文介绍了如何使用django-sitetree?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 django-sitetree ,但我不明白如何做步骤3,它是:

I am trying to use django-sitetree but I don't understand how to do step 3 which is:

转到Django管理站点并添加一些树木树项目。

"Go to Django Admin site and add some trees and tree items."

在管理面板中做一个sitetree?我相信第一步是为您要添加的网站树选择一个别名。

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

下一步是添加网站树项目。在这个页面上,你必须选择父母,标题,网址。考虑到我的应用程序是动态的url结构像这样 localhost:8000 / categoryname / entryname 如何选择网址?

The next step is to add "Site Tree Item". On this page you have to choose parent, title, url. Considering my app is dynamic with url structure like this localhost:8000/categoryname/entryname how do I choose urls?

我正在尝试在我的模板中添加面包屑。

By the way I am trying to add breadcrumbs in my templates.

推荐答案

创建一个树:


  1. 转到站点管理面板;

  2. 点击+添加附近'站点树';

  3. 为您的sitetree输入别名,例如'maintree'。

    你将通过模板标签中的这个别名来处理你的树;

  4. 按添加网站树项;

  5. 创建第一个项目:

  1. Goto 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:


父级:因为它将是根目录没有父母。

标题:让它成为我的网站。

URL:此网址是静态的,所以放这里'/'.

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 '/'.


  • 创建第二个项目(将从你的'categoryname / entryname'处理'categoryname') :

  • Create second item (that one would handle 'categoryname' from your 'categoryname/entryname'):


    父母:从第5步选择我的网站项目。

    标题:放在这里'Category#{{category.id}}'。

    URL:将命名URL'category-detailed category.name'。

    在其他设置中:选中 URL作为模式复选框。

    Parent: Choose 'My site' item from step 5.
    Title: Put here 'Category #{{ category.id }}'.
    URL: Put named URL 'category-detailed category.name'.
    In 'Additional settings': check 'URL as Pattern' checkbox.


  • 创建第三个项目(将处理'

  • Create third item (that one would handle 'entryname' from your 'categoryname/entryname'):


    父母:选择类别#{{category id}}'项目。

    标题:放在这里'Entry#{{entry.id}}'。

    URL :将指定的URL'entry-detailed category.name entry.name'。

    在其他设置中:选中 URL作为模式复选框。 p>

    Parent: Choose 'Category #{{ category.id }}' item from step 6.
    Title: Put here 'Entry #{{ entry.id }}'.
    URL: Put named URL 'entry-detailed category.name entry.name'.
    In 'Additional settings': check 'URL as Pattern' checkbox.


  • 将{%load sitetree%}放入yor模板以访问sitetree标签。


  • 将{%sitetree_breadcrumbs frommaintree%}放入您的模板中以渲染面包屑。






  • 步骤6和7需要一些说明:


    Steps 6 and 7 need some clarifications:


    • 在标题中,我们使用Django模板变量,它将像在模板中一样被解析。

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


    例如:您为'categoryname'(让我们称之为'detailed_category')将类别对象传递给模板
    作为类别变量。假设category对象具有'id'属性。
    在您的模板中,您可以使用{{category.id}}来呈现ID。而在步骤6中,我们对于站点树项目只需

    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 '{{ category.id }}' to render id. And we do just the same for site tree item in step 6.


  • 在URL中,我们使用Django的命名网址格式(文档)。这几乎与使用Django的网址标签几乎相同在模板中。

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


    您的步骤6,7的URL配置应包括:

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

    url (r'^(?P< category_name> \S +)/(?P< entry_name> \S +)/ $','detailed_entry',name ='条目详细 br>
    url(r'^(?P< category_name> \S +)/ $','detailed_category',name ='类别详细'),

    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'),

    因此,将第7步中的entry-detailed category.name entry.name放入URL字段,我们告诉sitetree将该sitetree项目与名为entry-detailed的URL相关联,传递给它category_name和entry_name参数。

    So, putting 'entry-detailed category.name entry.name' 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.


  • 我希望这个描述应该填写文档差距% )

    I hope this description should fill the documentation gap %)

    这篇关于如何使用django-sitetree?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆