0

我是 Django 的新手,目前正在建立一个网站。我已经下载了django-wiki 版本 0.4a3,以便为我的网站提供一个 wiki 应用程序。一切正常,开箱即用。但是不是将根文章显示为主页,而是如何显示根文章下所有文章的列表,以便用户只需单击任何子文章即可打开该文章?目前,用户必须点击一个菜单选项来向上浏览一个级别或在当前级别浏览以获得该给定级别的所有文章的列表。我觉得这相当乏味。我宁愿有一个“Windows Explorer 树和分支”导航,例如,

root
|_child 1
| |_child 1.1
| |_child 1.2
|
|_child 2
| |_child 2.1
|   |_child 2.1.1
|
|_child 3

请注意,我问的是如何获取根文章下的所有文章列表,而不是如何创建模板来实现树和分支文章导航器。一旦我知道如何获取所有文章的列表,我想我可以实现必要的 HTML 和 CSS 来拥有这种导航器。我很感激任何指示。

PS我之前尝试过官方的django-wiki google support group,但我认为那里的支持已经死了。我的两个问题都没有得到回答,更不用说阅读了(我只得到 1 次观看——这实际上是我的观看次数)。

克里斯。

4

2 回答 2

0

[解决了。]

制作article.html最初位于的副本wiki/templates/wiki/并将此副本放在您自己的项目templates/wiki/目录中。在要放置树目录的位置,添加类似于以下行的内容:

<!-- article.html -->
...
<h4>List of articles</h4>
<ul>
  <!-- Need to get the first article (root) -->
  {% url 'wiki:get' path=urlpath.root.path as rootpath %}
  <li>
    <a href="{{ rootpath }}">
      {{ urlpath.root.article.current_revision.title }}
    </a>
  </li>

  <!-- Now get all the descendent articles of the root -->
  {% for child in urlpath.root.get_descendants %}
    <!-- Don't list articles marked for deletion -->
    {% if not child.is_deleted %}
      {% with ''|center:child.level as range %}
        {% for _ in range %}<ul>{% endfor %}
        {% url 'wiki:get' path=child.path as childpath %}
        <li>
          <a href="{{ childpath }}">
            {{ child.article.current_revision.title }}
          </a>
        </li>
        {% for _ in range %}</ul>{% endfor %}
      {% endwith %}
    {% endif %}
  {% endfor %}
</ul>

你可以想象上面的代码。我是 Django 的新手(以及使用 django-wiki),所以这可能不是最干净或最有效的方法,但上述方法对我来说是预期的。

优势:

  • 文章列表总是更新的,因此任何已删除的文章都会被删除并显示插入的新文章。

  • 树状层次结构直观地显示了所有可用的文章及其相互关系。这种视觉描述比默认的描述要好得多,甚至很难知道存在多少文章或嵌套了多深的文章。

坏处:

  • 根据 django-wiki 的源代码,get_descendents方法是一个昂贵的调用,但对于我的小站点,我没有注意到任何惩罚命中(到目前为止)。
于 2018-03-18T14:55:13.613 回答
0

假设您的结构不超过 10 深:

[article_list depth:10]

把它放在你的根文章中。

于 2020-02-07T00:04:54.943 回答