【问题标题】:Django Paginated Comments .. is there any existing solutions?Django Paginated Comments .. 有没有现有的解决方案?
【发布时间】:2010-11-04 22:06:16
【问题描述】:

有没有针对 Django contrib.cmets 的现有分页解决方案?

我需要的只是一个简单的分页 django cmets,用于我使用的 Basic Blog 应用程序(来自 Django Basic Apps),使用 simple has_previous and has_next

我复制了 django.contrib.cmets 并尝试修改代码但没有成功。代码很难理解(django/contrib/cmets/templatetags/cmets.py),因为它由 Node 和 Parser 组成

这是我用于博客应用程序的 cmets.html 模板:

{% load comments markup %}
{% get_comment_list for object as comment_list %}
    {% if comment_list %}
    <div class="comments g_7 left">
        <a name="comments"></a>
        <div class="subtitle">Comments</div>
        {% for comment in comment_list %}
            {% if comment.is_public %}
            <div class="comment g_6" id="c{{ comment.id }}">
                <div class="comment_name g_6">
                <div class="comment_count right">
                    <a name="c{{ comment.id }}" href="{{ comment.get_absolute_url }}" {% ifnotequal comment.person_name null %}title="Permalink to {{ comment.person_name }}'s comment"{% endifnotequal %} class="comment_count">{{ forloop.counter }}</a></div>
                    Wrote by <strong>{% if comment.user_url %}<a href="{{ comment.user_url }}">{{ comment.user_name }}</a>{% else %}{{ comment.user_name }}{% endif %}</strong> on {{ comment.submit_date|date:"F j, Y" }} - {{ comment.submit_date|date:"P" }} 
                </div>
                <div class="comment_body g_6">{{ comment.comment|urlizetrunc:"60"|safe }}</div>
            </div>
            {% endif %}
        {% endfor %}

        <div class="clear"></div>
    </div>
    {% else %}
        No comments yet.
    {% endif %}

我认为问题在于 get_comment_list 模板标签:)

提前致谢

【问题讨论】:

    标签: django django-templates comments pagination templatetags


    【解决方案1】:

    我认为 django-pagination 可能是您正在寻找的。​​p>

    http://code.google.com/p/django-pagination/(提供截屏视频)

    【讨论】:

    • 嗨,谢谢你的回答 :) 其实我正在寻找特定的评论分页,有人可能以前做过(我想评论是一个共同的特点,一定有人在评论解决方案)但我认为您给我的链接可以提供解决方法:) 我会尝试使用它。谢谢!
    • +1 django-pagination 是解决这个问题的好方法;就像把它放在你的 INSTALLED_APPS 中并在你的模板中添加两行一样简单:“{% autopaginate comment_list %}”在你循环之前和(无论你想要分页控件在哪里)“{% pagination %}”。
    【解决方案2】:

    Django 也有一个内置的分页系统

    https://docs.djangoproject.com/en/dev/topics/pagination/

    【讨论】:

      猜你喜欢
      • 2023-02-06
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      相关资源
      最近更新 更多