Django

Contents:

Configuration

Django requires that one register Web-Templates before it will acknowledge the templates that it provides. Within ones WEBSITE/settings.py file add web_templates.django under INSTALLED_APPS as shown

INSTALLED_APPS = [...
  'web_templates.django',
  ...]

This makes the skeleton.html available for extention by the base template, base.html, of ones project.

Base Template(s)

Once Web-Templates is configured one should create a project wide base.html file for their website or web application. Create the WEBSITE/templates/base.html and extend the skeleton.html as necessary.

Ideally the base template of ones web application(s), APPLICATION/base.html, should both require and extend this template, base.html, to effect their respective views.

Generic Template

Even without a standardized template for Django ones finds that some combinations of the Django packages have implemented fairly similar conventions. Certainly it seems feasible to provide a generic template for ones project that will accommodate these conventions with the skeleton provided by Web-Templates.

The following describes such a generic base file (Click to download). First it extends the skeleton provided by Web-Templates.

{% extends 'skeleton.html' %}

The following template processors and tags may then be enabled as one requires.

Debug

It is common, under development, to view various debugging information. Django provides the debug template tag for this very purpose. Stefano suggests making this output available in the source of a page but hiding it normally.

{# block main_debug %}<div style="display:none;"><pre>{% debug|escape %}</pre></div>{% endblock main_debug #}

Static Files

The base template makes the media and static files available globally within a projects’ templates. It might be best to handle this on the application level though

{# load staticfiles #}
Site Trees

Commonly one also needs to include some form of navigational component; sitetrees provides a thorough yet highly configurable structure for this.

{# load sitetree #}