Skip to main content

Django Materialize Nav

This library was created to make django work with materializecss.

Setup

Install the library.

# project/settings.py

INSTALLED_APPS = [
    "materialize_nav",
    ...
]

Setup Context Processors

Materialize 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': [
                ...
                'materialize_nav.context_processors.get_context',
            ],
        },
    },
]

Alternative way to get the standard context for views

# views.py

from materialize_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', primary_color='teal')

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

Style

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

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


{% block nav_items %}
    <li><a href="sass.html">Sass</a></li>
    <li><a href="badges.html">Components</a></li>
    <li><a href="collapsible.html">JavaScript</a></li>
{% endblock %}


{% block sidenav_items %}
    {# One option is to override "materialize_nav/sidenav_items.html" #}
    {# OR use "block sidenav_items" and list your items or include another template. #}
    {# This makes the sidenav items reusable in other templates #}
    {% include "my_app/sidenav_items.html" %}
{% endblock %}


{% block contents %}
<div class="row">
    <div class="col s12 m9 l10">
        <p>My Content goes here</p>
    </div>
</div>
{% endblock %}

Styling controls

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

  • MATERIALIZE_SITE_NAME

  • MATERIALIZE_TITLE

  • HIDE_CONTAINER

  • SHOW_SIDENAV

  • FIXED_SIDENAV

  • PRIMARY_COLOR

  • SECONDARY_COLOR

  • PRIMARY_COLOR_LIGHT

  • PRIMARY_COLOR_DARK

  • SUCCESS_COLOR

  • ERROR_COLOR

  • LINK_COLOR

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

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

MATERIALIZE_HIDE_CONTAINER = False  # If True make the page take up the full width
MATERIALIZE_SHOW_SIDENAV = True  # If True have a menu button available to open up the side navigation menu
MATERIALIZE_FIXED_SIDENAV = False  # If True and SHOW_SIDENAV make the side navigation menu always showing

MATERIALIZE_PRIMARY_COLOR = 'materialize-red lighten-2'
MATERIALIZE_SECONDARY_COLOR = 'teal'
MATERIALIZE_PRIMARY_COLOR_LIGHT = '#e51c23'
MATERIALIZE_PRIMARY_COLOR_DARK = None
MATERIALIZE_SUCCESS_COLOR = None
MATERIALIZE_ERROR_COLOR = None
MATERIALIZE_LINK_COLOR = None

USER_THUMBNAIL_PROPERTY = 'profile.thumbnail'  # For user.profile.thumbnail
USER_BACKGROUND_PROPERTY = 'profile.background'  # For user.profile.background
# USER_THUMBNAIL = 'accounts/default_user.png'  # This is a default image
# USER_BACKGROUND_IMAGE = 'accounts/default_user.png'  # This is a default image

Styling process

There are two methods for changing the default coloring for Materialize CSS.

  • The old method is to use the templatetag include_dynamic_css which would use the django template system to generate a style tag with the proper css classes overridden.

  • The new method only requires using the base.html. It includes the materialize_nav/materialize_nav_colors.js file which uses javascript to create a style tag to edit the proper css classes. This method should require less work from django to change the style.

Goals

My original goal was to create an easier way to use materialize css with django. When I first started forms did not format properly and I thought navigation was a pain. Unfortunately, my original approach made this library a strong coupled to your django app which was a terrible design decision. I am trying to simplify this library to help style django apps quickly and without a lot of settings.

Metadata

Release files for django-materialize-nav 1.2.0

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-materialize-nav 1.2.0
File Size Uploaded
django_materialize_nav-1.2.0.tar.gz 23.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-materialize-nav 1.2.0
File Interpreter ABI Platform
django_materialize_nav-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.5 MB

Release files / django_materialize_nav-1.2.0.tar.gz

Download URL django_materialize_nav-1.2.0.tar.gz
Size 23.7 MB
Tags Source
SHA-256 checksum
How to use checksums
6dfec1733aafda4ea013fa601aed1fd55922e10ae7510c05ae7e855de8c310a3
BLAKE2b-256 checksum
How to use checksums
11cb72307038a2e83d6312da5f7d8d177e5d64ee161935dd6c630c5cabc91225
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Release files / django_materialize_nav-1.2.0-py3-none-any.whl

Download URL django_materialize_nav-1.2.0-py3-none-any.whl
Size 23.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
2f55a03f1ea4c119ac185bfa881d67cf585b27afded7cb8ca181d6356b3049d0
BLAKE2b-256 checksum
How to use checksums
33f6b4cde4df05f4b61d5204cd206c61d4512289bcf53f87df938b18b270ebde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.2.3

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

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