Skip to main content

Base HTML templates for DBCA Django projects

Project description

DBCA Django web template

This project consists of a basic Django application containing HTML templates that provide a starting point for web applications used by the Department. The base template consists of a mobile-friendly HTML5 template with a fixed top navbar, plus static assets. The project also contains functional examples of login and logged out templates.

The base templates are based upon HTML5 Boilerplate.

Development

The recommended way to set up this project for development is using uv to install and manage a Python virtual environment. With uv installed, install the required Python version (see pyproject.toml). Example:

uv python install 3.12

Change into the project directory and run:

uv python pin 3.12
uv sync

Activate the virtualenv like so:

source .venv/bin/activate

Run unit tests using pytest (or tox, to test against multiple Python versions):

pytest -sv
tox -v

Releases

Tagged releases are built and pushed to PyPI automatically using a GitHub workflow in the project. Update the project version in pyproject.toml and tag the required commit with the same value to trigger a release. Packages can also be built and uploaded manually, if desired.

Build the project locally using uv, publish to the PyPI registry using the same tool if you require:

uv build
uv publish

Installation

  1. Install via pip: pip install webtemplate-dbca.
  2. Add 'webtemplate_dbca' to INSTALLED_APPS.
  3. Ensure that the staticfiles application is included and configured correctly.
  4. (Optional) Ensure that you have defined the following named URLs: login and logout (this requirement can be overriden, see below).
  5. Extend the included base template by placing the following at the head of your own templates, e.g. {% extends "webtemplate_dbca/base_b4.html" %}
  6. Place page content within the required blocks (see below).

Included CSS and JavaScript

The base_b4/base_b5 templates include the following CSS and JavaScript assets:

  • Modernizr (HTML5 polyfills)
  • Bootstrap 4 or 5 (CSS & JS)
  • jQuery (base/base_b4 templates)

Additional styling can be included using the extra_style or extra_js blocks, like so::

{% load static from staticfiles %}

{% block extra_style %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'css/custom.css' %}">
{% endblock %}

You can also overide the base_style and base_js blocks completely to use different CSS or JS libraries. Note that you will also need to replace the top_navbar block contents if you replace the base Bootstrap CSS & JS.

The version of jQuery which is loaded in the base is by default a slimmed-down minimal version of the library. To include a different specific version, override the jquery_version block. Example::

{% block jquery_version %}
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
{% endblock %}

NOTE: There is no jQuery loaded with the base_b5 template, as it was dropped as a requirement of Bootstrap.

Template blocks

The base template contains a number of block tags that are used to render the content of your project. The main template content blocks are as follows:

  • navbar_links - used to define navigation links in the top navbar.
  • navbar_auth - used to display either a Login or Logout link.
  • page_content - used to contain the page's main content.
  • page_footer - used to contain a page footer area.

Note that the navbar_auth block contains {% url %} templatetags with named URLs called login and logout. If this is not required or inappropriate for your project, simply override the navbar_auth block in a base template like so::

{% block navbar_auth %}{% endblock %}

In addition, a number of context variables are defined:

  • page_title - used to populate the page <title> tags.
  • site_title - used to populate the projects's title in the top navbar.
  • site_acronym - used to populate a shorter title in the navbar (B4 template).

Context variables should be passed to templates in every view.

Bootstrap 4 & 5 examples

The following examples apply to the base_b4.html and base_b5.html templates.

To extend the base template with an optional row to display alert messages plus a shaded footer div, try the following (further page content is then injected to the page_content_inner block)::

{% extends "webtemplate_dbca/base_b4.html" %}

{% block extra_style %}
<style>
    .footer {background-color: lightgrey}
</style>
{% endblock %}

{% block page_content %}
    <div class="container-fluid">
        <!-- Messages  -->
        {% if messages %}
        <div class="row">
            <div class="col">
                {% for message in messages %}
                <div class="alert{% if message.tags %} alert-{{ message.tags }}{% endif %}">
                    {{ message|safe }}
                </div>
                {% endfor %}
            </div>
        </div>
        {% endif %}

        <div class="row">
            <div class="col">
                {% block page_content_inner %}{% endblock %}
            </div>
        </div>
    </div>
{% endblock %}

{% block page_footer %}
<footer class="footer mt-auto py-3">
    <div class="container-fluid">
        <div class="row">
            <div class="col">
                <small class="float-right">&copy; Department of Biodiversity, Conservation and Attractions</small>
            </div>
        </div>
    </div>
</footer>
{% endblock page_footer %}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webtemplate_dbca-1.8.3.tar.gz (47.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webtemplate_dbca-1.8.3-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file webtemplate_dbca-1.8.3.tar.gz.

File metadata

  • Download URL: webtemplate_dbca-1.8.3.tar.gz
  • Upload date:
  • Size: 47.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.2

File hashes

Hashes for webtemplate_dbca-1.8.3.tar.gz
Algorithm Hash digest
SHA256 caacf886c5b59bf6b53edc8ffcc3602fd51f4c5c719cb491ffc3e5e166535b5d
MD5 afdb32cefbeaea93e0fe94e5967c2841
BLAKE2b-256 09bbc5148bfb97a5f4c9df60036efc8036f65cd246f3ee0e299654a33946e6ed

See more details on using hashes here.

File details

Details for the file webtemplate_dbca-1.8.3-py3-none-any.whl.

File metadata

File hashes

Hashes for webtemplate_dbca-1.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 85da2f6d8f121c6abb66ca2d98ec4b1a7bd603d574ecb3276996ab003144ef1e
MD5 f3862a5d8fa0e61959ee0b92cc2179dc
BLAKE2b-256 f389b523a67691f5efc52bb1abd0d5f90ad27f4442ab596a1b9bdb16f2f65f44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page