Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Django app for determining site section by request.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 section
Octocat-spinner-32 .gitignore
Octocat-spinner-32 AUTHORS.rst
Octocat-spinner-32 CHANGELOG.rst
Octocat-spinner-32 LICENSE
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.rst
Octocat-spinner-32 setup.py
Octocat-spinner-32 test_settings.py
README.rst

Django Section

Django app for determining site section by request.

Contents

Installation

  1. Add section.context_processors.section to your TEMPLATE_CONTEXT_PROCESSORS setting:

    TEMPLATE_CONTEXT_PROCESSORS = (
        ...other context processors...,
        "section.context_processors.section",
    )
    
  2. Add SECTIONS setting to your settings file in the form:

    # Tuple of dictionaries used to match URL pattern names to site sections.
    # example: ({'name': '<section name>', 'matching_pattern_names': ('<url_name1>', '<url_name2>')},)
    SECTIONS = (
        {'name': 'home', 'matching_pattern_names': ('home',)},
    )
    

Usage

If you're using generic views or RequestContext you'll now automagically have a section variable added to context and available in your templates containing the value of name as defined for the current view in your SECTIONS setting.

NOTE: If the current path can not be resolved to a defined section, the first section as defined in the SECTION settings is returned. This allows you to setup a global fallback section, i.e. home.

Something went wrong with that request. Please try again.