Skip to main content

This library was created to make django work with some generic bootstrap4 templates. This library uses the basic functionality from django-bootstrap4. I use it to match templates with my django_materialize_nav library.

Setup

Install the library.

# project/settings.py

INSTALLED_APPS = [
    "bootstrap4_nav",
    ...
]

Setup Context Processors

Bootstrap4_nav comes with a context processor to use some settings to change the default base styling.

# Context Processor to work with settings
TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'context_processors': [
                ...
                'bootstrap4_nav.context_processors.get_context',
            ],
        },
    },
]

Alternative way to get the standard context for views

# views.py

from bootstrap4_nav.context_processors import get_context


def show_page(request):
    # Get the context with the style settings
    context = get_context(site_name='demo', title='Basic Content')

    context["object"] = "MyObject"
    return render(request, "my_page.html", context)

Style

The base template can be used by extending the materialize base nav.

{% extends "bootstrap4_nav/base.html" %}


{% block nav_items %}
    <li class="navbar-item{% if title == 'Page1' %} active{% endif %}"><a class="nav-link" href="/">Page1</a></li>
    <li class="navbar-item{% if title == 'Page2' %} active{% endif %}"><a class="nav-link" href="/">Page2</a></li>
    <li class="navbar-item{% if title == 'Page3' %} active{% endif %}"><a class="nav-link" href="/">Page3</a></li>
{% endblock %}

{% block contents %}
<div>
    <p>My Content goes here</p>
</div>
{% endblock %}

Styling controls

Bootstrap4_nav comes with several style options used in the template context variables listed below.

  • BOOTSTRAP4_SITE_NAME

  • BOOTSTRAP4_TITLE

If you went through the Setup Context Processors step then you can modify several settings to change the default style. This is an alternative to manually providing all of the template context variables.

# settings.py

BOOTSTRAP4_SITE_NAME = None  # Display this name in the navbar as the main name
BOOTSTRAP4_TITLE = None  # This is the page title displayed as the browser tab name

Metadata

Release files for django-bootstrap4-nav 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-bootstrap4-nav 0.0.1
File Size Uploaded
django_bootstrap4_nav-0.0.1.tar.gz 6.8 kB Details

Release files / django_bootstrap4_nav-0.0.1.tar.gz

Download URL django_bootstrap4_nav-0.0.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
71cd33c58e7e833e9de9e79f45300ef1b6e939fe40c53638171a2cef18edf562
BLAKE2b-256 checksum
How to use checksums
1025809045d9b8bf4bea5777b349136d209d329f4182eefe8355a5c9a86d5689
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page