python 2.7 - Django comments pagination isnt working -
there trouble i'm new django , there issue can't understand,
there 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 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> {% 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 }}">«</a></li> {% else %} <li class="arrow unavailable"><a href="">«</a></li> {% endif %} {% 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 }}/">»</a></li> {% else %} <li class="arrow unavailable"><a href="">»</a></li> {% endif %} </ul> </div> </div> {% endblock %}
this 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 on article page appeared pages pagination, when i'm clicking on second page, example, it changing url, new comments not appearing, old ones.
what should do right? thank much!
your variable name comments_page_number
uses default value. name second parameter in url route match variable name.
Comments
Post a Comment