Django templates folders

Did you set TEMPLATE_DIRS in your settings.py? Check and make sure it is set up correctly with absolute paths. This is how I make sure it is properly set: settings.py PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) TEMPLATE_DIRS = ( # Put strings here, like “/home/html/django_templates” or “C:/www/django/templates”. # Always use forward slashes, even on Windows. # Don’t forget … Read more

How to iterate over nested dictionaries in django templates

Since you’re familiar with python, the following is logically how you would want to iterate through your dictionary in a Django template: for key,value in harvest_data.items(): … print key … for key2,value2 in value.items(): … print key2 … for key3,value3 in value2.items(): … print “%s:%s”%(key3,value3) In your template, this translates as follows: {% for key, … Read more

How organize pagination with a large number of pages in Django project?

I change pagination.html. Please try this. <nav aria-label=”pagination” class=”pagination_area”> <div class=”row”> {% if page.end_index > 0 %} <div class=”col-sm-12 col-md-5 d-none d-md-block”> <p>Showing {{ page.start_index }} to {{ page.end_index }} of {{ page.paginator.count}}.</p> </div> {% endif %} {% if page.paginator.num_pages > 1 %} <div class=”col-sm-12 col-md-7 dataTables_pager”> <ul class=”pagination”> {% if page.has_previous %} <li class=”page-item”> … Read more

Django {{ MEDIA_URL }} blank @DEPRECATED

You need to add the RequestContext in your render_to_response for the context processors to be processed. In your case: from django.template.context import RequestContext context = {‘latest’: p} render_to_response(‘Question/latest.html’, context_instance=RequestContext(request, context)) From the docs: context_instance The context instance to render the template with. By default, the template will be rendered with a Context instance (filled with … Read more