I created a tag like this:
@register.inclusion_tag('post/comment_block.html')
def limit_amount_in_a_page(page_nr=1, post_id=1, amount=5):
starting_index = page_nr*amount
for index in range(starting_index, starting_index + amount):
dosomething()
has_prev = (page_nr != 0)
has_next = ((page_nr + 1) * amount) < comments.count()
return {
something
}
The problem is : page_nr is always not an int.
and this is how I call the tag and assign the value to page_nr in the tag:
{% limit_amount_in_a_page page_nr=my_page_nr post_id=post.id amount=4 %}
this is where the value of my_page_nr comes from:
def to_post_page(request, post_id, page_nr):
post = get_object_or_404(Post, id=post_id)
form = CommentForm()
comments = Comment.objects.filter(pk=post_id)
return render(request, 'post/posts.html', {
'post': post,
'form': form,
'comments': comments,
'my_page_nr': page_nr,
})
this is the url calling the view:
url(r'^(?P<post_id>[0-9]+)/(?P<page_nr>[0-9]+)/$', views.to_post_page, name="post"),
{% for post in my_posts %}
<li><a href="{% url 'forum:post' post.id 0 %} ">{{post.title}}</a></li>
{% endfor %}
The value passed to this url tag should be a int. As you can see, I passed a 0. Really appreciate for any help!