Skip to main content
Context Layers for Django
==========================

This app provides "context layers" for Django templates. A context
layer is a model object that contributes data to a template during
rendering.

Context layers match on URL paths. When a match is found, the model
record is asked for data to contribute, and that data is sent along to
the template context.

Context layers have activation dates. You can set the layer to turn
on (become active) at a specific date/time, and also to turn off
(become inactive).

Context layers were originally developed to provide:

* Additional CSS to a page; see the sample app for an implementation
* Selective enabling or disabling of adverts
* Conditional markup during a site beta period

This package doesn't provide any concrete models, so you still have to
provide your own models to specify what your layers do (in other
words, how your layers contribute to the context). Again, see the
sample app for an implementation.


Install
-------

Pull down the app:

$ pip install django-contextlayers

Add it to your `INSTALLED_APPS`:

INSTALLED_APPS = (
...
'contextlayers'
)

Then include the context processor in your settings:

TEMPLATE_CONTEXT_PROCESSORS = (
...
'contextlayers.context_processors.layer_tool',
)


Making Your Own Layers
----------------------

First you define a layer class. You'll probably want to subclass
`LayerBase`, but it's not strictly necessary. You must include a
`LayerMeta` property, and you must supply a `contribute_to_context`
method. Example from the sample:

from contextlayers.models import LayerBase

class ThemeLayer(LayerBase):
markup = models.TextField(...)

class LayerMeta:
pass

def contribute_to_context(self, layer_context, global_context):
layer_context.setdefault('theme', []).append(self.markup)

When this layer is matched, the content of the `markup` field will be added
to the template at `layers.theme`.

Next, sync your database:

$ ./manage.py syncdb

The layers won't be visible until you add support to your templates.
For example:

{% for css in layers.theme %}
{{ css|safe }}
{% endfor %}

What you do with `layers.*` depends on what the layer provides to the
context and how your templates should use it.

Finally, define the layer records in the Django admin. Take note of
the help text for the dates and path values.

Metadata

Release files for django-contextlayers 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-contextlayers 0.1
File Size Uploaded Provenance Actions
django-contextlayers-0.1.tar.gz 4.6 kB Without provenance Details for django-contextlayers-0.1.tar.gz

Release files / django-contextlayers-0.1.tar.gz

Download URL django-contextlayers-0.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a99fcb41dddaee89b416343b24f29fa2db08782a156dc1095afb7221d45384b0
BLAKE2b-256 checksum
How to use checksums
ea80ce78a1e18c97b3c9936c5dde791c156b6a153183de27ebb5ca882c5a1a2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-contextlayers 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

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