Skip to main content

Define content fragments in Django templates and store their contents in the database. This is yet another take on the idea previously implemented in django-flatblocks, django-chunks etc.

Project description

This reusable Django app lets you store snippets of text (“grains”) in the database keyed by arbitrary strings. It’s the same idea implemented previously in django-chunks, django-flatblocks, django-tinycontent and others.

Usage

Install with pip install django-grains.

Add grains to INSTALLED_APPS in your project’s Django settings.

Run manage.py syncdb or manage.py migrate (if you’re using South) to create the database tables.

In your templates, create placeholders for grains:

{% load grains_tags %}

{% grain "front-page-title" %}The default title of the front page{% endgrain %}

{% grain "front-page-subtitle" "text/plain" %}The default subtitle of the front page{% endgrain %}

{% grain "front-page-content" "text/html" %}
    <p>This is the default HTML content of the front page.</p>
{% endgrain %}

The first argument to {% grain %} is the unique identifier of the grain. The second argument is the content type which could be used to choose the editor widget for the value in Django’s admin interface. The second argument can be omitted in which case it defaults to text/plain.

Project details


Download files

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

Source Distribution

django-grains-0.1.tar.gz (2.0 kB view details)

Uploaded Source

File details

Details for the file django-grains-0.1.tar.gz.

File metadata

File hashes

Hashes for django-grains-0.1.tar.gz
Algorithm Hash digest
SHA256 2c644eff5dd6abfb16b9468c2a7d22be8d17f0bfd0cdb0437c0f9f4cefec55e2
MD5 ecbf6d12d5aa6d57587cb1cd439b8e91
BLAKE2b-256 6ea720efedd7b31ab6cceb38e24f68b6a32734331a3b67d16e15479848d98309

See more details on using hashes here.

Supported by

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