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

查看:22
本文介绍了如何使用 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."

如何在管理面板中创建站点树?我相信第一步是为您要添加的站点树"选择一个别名.

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.

下一步是添加站点树项".在此页面上,您必须选择父级、标题、网址.考虑到我的应用程序是动态的,具有像 localhost:8000/categoryname/entryname 这样的 url 结构,我该如何选择 url?

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. 输入站点树的别名,例如'主树'.
    您将在模板标签中通过此别名来处理您的树;
  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:这个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 as Pattern"复选框.

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

    家长:从第 6 步中选择类别#{{ category.id }}"项目.
    标题: 放在这里 'Entry #{{ entry.id }}'.
    URL: 将命名 URL 'entry-detailed category.name entry.name'.
    在其他设置"中:选中URL as Pattern"复选框.

    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 %}"放入您的模板中以访问站点树标签.
  • 将 '{% sitetree_menu from "maintree" %}' 放入模板以呈现菜单.
  • 将 '{% sitetree_breadcrumbs from "maintree" %}' 放入模板以呈现面包屑.
  • <小时>

    第 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")创建视图以将类别对象传递给模板作为类别"变量.假设类别对象具有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 的命名 URL 模式(文档).这几乎与使用 Django 'url' 标签相同在模板中.

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

    步骤 6、7 的 urls 配置应该包括:

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

    url(r'^(?Purl(r'^(?P

    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 将该站点树项与名为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天全站免登陆