Hello, I've got a couple questions here. The first one is kinda long. Sorry ;)
1. I'm using two custom inclusion tags for different styles of pagination in a project (takes_context=False). Each tag is registered to a different pagination template HTML. Therefore each tag hands-off a context to it's registered template that includes a page object and paginator from django.core.paginator.Paginator. The inclusion tags are invoked in the "index.html" file. The query I'm running in my view.py is trivial and when I've tested this WITHOUT pagination inclusion tags it's super quick. However, the second I start using the inclusion tags it's bogged down and slow. Why is this? (all code provided below) The only think I can think is that since the view.py is creating a paginator and page object and handing that context off to the "index.html" and each tag function is also handing off a page and paginator object (not those from index.html context but new ones) to their respective templates that I'm producing redundancies. (see the code snippet below) If the above is correct then will using 'takes_context=True' when registering my tag produce a speedier response because I'm relying on using the first paginator or page object passed to "index.html" and handing it off to my tags and tag templates? 2. What ways do the real developers out there track where the bottlenecks are in your Django app if it's running slow? Both in terms of monitoring query times and also tag and template compilation and run times? CODE SNIPPET ------------------------------------------------------------------------------------------ # tail of my view.py function calling index.html # Create our paginator paginator = Paginator(records, 5) # Handle out of index requests try: p = paginator.page(page) except (EmptyPage, InvalidPage): p = paginator.page(paginator.num_pages - 1) return render_to_response('index.html', { 'page_objects' : p, 'items_per_page' : items_per_page, 'paginator' : paginator, 'page' : page, }, context_instance=RequestContext(request)) - - - # My index.html file calling the custom inclusion tags <!-- html --> {% pagination_links request paginator %} <!-- html --> {% pagination_next_prev request paginator %} <!--html --> - - - # My inclusion tags from django import template import urllib register = template.Library() @register.inclusion_tag("pagination_links.html") def pagination_links(request, paginator, adjacent_pages=2): raw_params = request.GET.copy() try: page = raw_params.get('page',1) except ValueError: page = 1 p = paginator.page(page) try: del raw_params['page'] except KeyError: pass params = urllib.urlencode(raw_params) #Adjacent Links Logic startPage = max(p.number - adjacent_pages, 1) if startPage <=3: startPage = 1 endPage = p.number + adjacent_pages + 1 if endPage >= paginator.num_pages - 1: endPage = paginator.num_pages + 1 page_numbers = [n for n in range(startPage, endPage) if n > 0 and n <= paginator.num_pages] return {'request' : request, 'paginator' : paginator, 'p' : p, 'params' : params, 'page_numbers' : page_numbers, 'show_first' : 1 not in page_numbers, 'show_last' : paginator.num_pages not in page_numbers, } @register.inclusion_tag("pagination_prev_next.html") def pagination_prev_next(request, paginator, adjfrom django import template import urllib register = template.Library() @register.inclusion_tag("pagination_links.html") def pagination_links(request, paginator, adjacent_pages=2): raw_params = request.GET.copy() try: page = raw_params.get('page',1) except ValueError: page = 1 p = paginator.page(page) try: del raw_params['page'] except KeyError: pass params = urllib.urlencode(raw_params) #Adjacent Links Logic startPage = max(p.number - adjacent_pages, 1) if startPage <=3: startPage = 1 endPage = p.number + adjacent_pages + 1 if endPage >= paginator.num_pages - 1: endPage = paginator.num_pages + 1 page_numbers = [n for n in range(startPage, endPage) if n > 0 and n <= paginator.num_pages] return {'request' : request, 'paginator' : paginator, 'p' : p, 'params' : params, 'page_numbers' : page_numbers, 'show_first' : 1 not in page_numbers, 'show_last' : paginator.num_pages not in page_numbers, } @register.inclusion_tag("pagination_prev_next.html") def pagination_prev_next(request, paginator, adjacent_pages=2): raw_params = request.GET.copy() try: page = raw_params.get('page',1) except ValueError: page = 1 p = paginator.page(page) try: del raw_params['page'] except KeyError: pass params = urllib.urlencode(raw_params) return {'request' : request, 'paginator' : paginator, 'p' : p, 'params' : params, } acent_pages=2): raw_params = request.GET.copy() try: page = raw_params.get('page',1) except ValueError: page = 1 p = paginator.page(page) try: del raw_params['page'] except KeyError: pass params = urllib.urlencode(raw_params) return {'request' : request, 'paginator' : paginator, 'p' : p, 'params' : params, } - - - # My pagination_links.html tag template <div class="pagination"> {% if p.has_previous %} <a href="{{request.path}}? page={{p.previous_page_number}}"><img src="{{root_relative_url}}media/ images/pagination-prev.gif" alt="<"/> </a> {% endif %} {% if show_first %} <a href="{{request.path}}?page=1">1</a> ..... {% endif %} {% for linkpage in page_numbers %} {% ifequal linkpage p.number %} <strong>{{p.number}}</strong> {% else %} <a href="{{request.path}}?page={{ linkpage }}">{{ linkpage }}</a> {% endifequal %} {% endfor %} {% if show_last %} ..... <a href="{{request.path}}?page= {{ p.paginator.num_pages }}">{{ p.paginator.num_pages }}</a> {% endif %} {% if p.has_next %} <a href="{{request.path}}?page={{p.next_page_number}}"><img src="{{root_relative_url}}media/images/pagination-next.gif" alt=">"/> </a> {% endif %} </div> # My pagination_prev_next.html tag template {% if p.has_other_pages %} Page {{ p.number }} of {{ paginator.num_pages }} {% if p.has_previous %} <a href="{{ request.path }}?page={{ p.previous_page_number}}"><img src="{{root_relative_url}}media/images/pagination-prev.gif" alt="<" / ></a> {% else %} <a href=""><img src="{{root_relative_url}}media/images/pagination- prev.gif" alt="<" /></a> {% endif %} {% if p.has_next %} <a href="{{ request.path }}?page={{ p.next_page_number}}"><img src="{{root_relative_url}}media/images/pagination-next.gif" alt=">" / ></a> {% else %} <a href="#"><img src="{{root_relative_url}}media/images/pagination- next.gif" alt=">" /></a> {% endif %} {% endif %} </div> -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.