0

there is a trouble I'm new to django and there is an issue I can't understand,

there is a view:

def article(request, article_id = 1, comments_page_number = 1):
    all_comments = Comments.objects.filter(comments_article_id = article_id)
    paginator = Paginator(all_comments, 2)
    comment_form = CommentForm
    args = {}
    args.update(csrf(request))
    args['article'] = Article.objects.get(id = article_id)
    args['comments'] =  paginator.page(comments_page_number)
    args['form'] = comment_form
    args['username'] = auth.get_user(request).username
    return render_to_response('article.html', args)

there is a template article.html

{% extends 'main.html' %}

{% block article %}
<h4>{{article.article_date}}</h4>
<h2>{{article.article_title}}</h2>
<p> {{article.article_body}}</p>
<hr>

<div class="large-offset-1 large-8 columns">
<p>Комментарии: </p>
{% for comment in comments %}
    <p>{{comment.comments_text}}</p>
    <hr>
{% endfor %}
    {% if username %}
    <form action="/articles/addcomment/{{article.id}}/" method="POST" >
        {% csrf_token %}
        {{form }}
        <input type="submit" class="button" value="Add comment">
    </form>
    {% endif %}
</div>
    <div class="row">
        <div class="large-3 large-offset-5 columns">
            <ul class="pagination">
                {% if comments.has_previous %}
                    <li class="arrow"><a href="/articles/get/{{article.id}}/comments/{{ comments.previous_page_number }}">&laquo;</a></li>
                {% else %}
                    <li class="arrow unavailable"><a href="">&laquo;</a></li>
                {% endif %}
                {% for page in comments.paginator.page_range %}
                    {% if page == comments.number %}
                        <li class="current"><a href="/articles/get/{{article.id}}/comments/{{ page }}/">{{ page }}</a></li>
                    {% else %}
                        <li><a href="/articles/get/{{article.id}}/comments/{{ page }}/">{{ page }}</a></li>
                    {% endif %}
                {% endfor %}
                {% if comments.has_next %}
                    <li class="arrow"><a href="/articles/get/{{article.id}}/comments/{{ comments.next_page_number }}/">&raquo;</a></li>
                {% else %}
                    <li class="arrow unavailable"><a href="">&raquo;</a></li>
                {% endif %}
            </ul>
        </div>
    </div>

{% endblock %}

this is my article/urls.py

urlpatterns = patterns('',
    url(r'^articles/get/(?P<article_id>\d+)/$','article.views.article'),
    url(r'^articles/get/(?P<article_id>\d+)/comments/(\d+)/$', 'article.views.article'),
)

after that on my article page appeared an pages pagination, but when I'm clicking on the second page, for example, it it is just changing my url, but new comments are not appearing, just old ones.

What should I do to do this right? Thank you very much!

4

2 回答 2

0

您的变量名称comments_page_number始终使用默认值。在 url 路由中命名您的第二个参数以匹配此变量名称。

于 2014-06-03T17:28:24.503 回答
0

你需要 :

url(r'^articles/get/(?P<article_id>\d+)/comments/(?P<comments_page_number>\d+)/$', 'article.views.this_article'),
于 2015-09-02T12:11:20.380 回答