Django Template Save operation result into a variable -


i have listing counter "2370" , page shows "12" item want calculate pages number, did solution below

{% widthratio listing.total_count 12 1 %} 

so, how can save result variable?

{% set total_pages =  widthratio listing.total_count 12 1 %} 

this 1 didn't work

if choose rohans comment, if write own templatetags, use assignment_tag (https://docs.djangoproject.com/en/1.7/howto/custom-template-tags/#assignment-tags, exists since django 1.4).

@register.assignment_tag def page_numbers(total_items, items_per_page):     if not total_items:          return 0     # int divisions round down (1 / 12 = 0), add 1 cover      return total_items / items_per_page + 1 

within template should use;

{% page_numbers listing.total_count 12 page_nrs %} 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -