• Stars
    star
    108
  • Rank 310,068 (Top 7 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created almost 12 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Circular template inheritance for Django
https://secure.travis-ci.org/stephenmcd/django-overextends.png?branch=master

Created by Stephen McDonald

Introduction

A Django reusable app providing the overextends template tag, a drop-in replacement for Django's extends tag, which allows you to use circular template inheritance.

The primary use-case for overextends is to simultaneously override and extend templates from other reusable apps, in your own Django project.

Example

Consider the following settings module and templates, with the apps app1 and app2 bundled in the project, for example's sake:

# settings.py
INSTALLED_APPS = (
    "app1",
    "app2",
    "overextends",
)
TEMPLATE_LOADERS = (
    "django.template.loaders.filesystem.Loader",
    "django.template.loaders.app_directories.Loader",
)
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates"),)

<!-- myproject/app1/templates/pages/page.html -->
<h1>Title</h1>
{% block main %}
<p>A paragraph in app1</p>
{% enblock %}
<footer>Copyright 2012</footer>

<!-- myproject/app2/templates/pages/page.html -->
{% overextends "pages/page.html" %}
{% block main %}
<p>A paragraph in app2, that wants to be on top of app1's main block</p>
{{ block.super }}
{% enblock %}

<!-- myproject/templates/pages/page.html -->
{% overextends "pages/page.html" %}
{% block main %}
{{ block.super }}
<p>A paragraph in the project's template directory, under the other main blocks</p>
{% enblock %}

The resulting HTML rendered when pages/page.html was loaded would be:

<h1>Title</h1>
<p>A paragraph in app2, that wants to be on top of app1's main block</p>
<p>A paragraph in app1</p>
<p>A paragraph in the project's template directory, under the other main blocks</p>
<footer>Copyright 2012</footer>

For a detailed analysis of why you would use this approach, how it works, and alternative approaches, read my initial blog post: Circular Template Inheritance for Django

Installation

The easiest way to install django-overextends is directly from PyPi using pip by running the following command:

$ pip install -U django-overextends

Otherwise you can download django-overextends and install it directly from source:

$ python setup.py install

Project Configuration

Once installed you can configure your project to use django-overextends by adding the overextends app to the INSTALLED_APPS in your project's settings module:

INSTALLED_APPS = (
    # ... other apps here ...
    'overextends',
)

For Django 1.9+ you must add overextends to the builtins key of your TEMPLATES setting:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'APP_DIRS': True,
        'OPTIONS': {
            'builtins': ['overextends.templatetags.overextends_tags'],
        }
    },
]

Note that while the overextends tag is provided by the package overextends.templatetags.overextends_tags, it is unnecessary to use {% load overextends_tags %} in your templates. Like the extends tag, overextends must be the first tag in your template, so it is automatically added to Django's built-in template tags, removing the need to load its tag library in each template.

More Repositories

1

mezzanine

CMS framework for Django
Python
4,715
star
2

django-socketio

WebSockets for Django
Python
1,312
star
3

cartridge

Ecommerce for Mezzanine
Python
697
star
4

django-forms-builder

Let users build forms in Django admin
Python
683
star
5

curiodb

Distributed NoSQL Database
Scala
512
star
6

drum

Reddit / Hacker News clone for Mezzanine
Python
392
star
7

hot-redis

Rich Python data types for Redis
Python
288
star
8

gnotty

IRC web client and bot framework
Python
159
star
9

two-queues

Benchmarking Redis and ZeroMQ pub-sub, using Python and Go
Go
105
star
10

gunicorn-console

A curses application for managing gunicorn processes.
Python
90
star
11

django-postgres-fuzzycount

Fast / fuzzy PostgreSQL counts for Django
Python
86
star
12

django-email-extras

PGP encrypted / multipart templated emails for Django
Python
75
star
13

filebrowser-safe

File manager for Mezzanine
Python
41
star
14

hg-github

A Mercurial extension for working with GitHub repositories.
Python
40
star
15

vimeo-deck

Synchronize Speaker Deck presentations with Vimeo videos.
JavaScript
28
star
16

gamblor

An online casino app built for Django Dash 2012
JavaScript
26
star
17

grappelli-safe

Admin skin for Mezzanine
CSS
25
star
18

snazzymaps-browser

Android app for searching and browsing Snazzy Maps
Java
24
star
19

grillode

A web-based chat application written in CoffeeScript for Node.js
CoffeeScript
23
star
20

drawnby

Drawn By is a collaborative real-time sketching app built for the 2011 Django Dash.
JavaScript
23
star
21

babbler

A Twitter bot that polls an RSS feed and posts its entries as tweets, with auto-generated hashtags.
Python
21
star
22

tastypie-msgpack

MsgPack support for Django Tastypie.
Python
21
star
23

django-shotgun

Test entire Django sites
Python
17
star
24

linkedout

Build PDF resumes with the LinkedIn API
Ruby
15
star
25

sphinx-me

Wraps your README-only projects in a dynamic Sphinx shell for hosting on http://readthedocs.org
Python
12
star
26

readertray

Cross platform desktop notifications for RSS
Python
9
star
27

indexed-tree-map

JDK's enhanced red-black tree map algorithm to support access by index
Java
9
star
28

otr

Combined GitHub and Bitbucket API.
Ruby
8
star
29

aspchat

Classic ASP chat application
ASP
8
star
30

bitbucket-batch

A tool for bulk updating access to bitbucket.org repos.
Python
8
star
31

grillo

A terminal based chat server and client.
Python
7
star
32

mezzanine.jupo.org

Mezzanine/Cartridge project and demo site
Python
6
star
33

ratemyflight

A web app built for the Django Dash hackathon 2010.
JavaScript
6
star
34

klout-feed

Receive your daily Klout score via RSS.
Ruby
6
star
35

slbuddy

Tool for tracking sales data in Secondlife.com
Python
3
star
36

virtualboxing

Utilities for comparing timings on bulk operations across databases in a distributed environment.
Ruby
3
star
37

cryptopals

Matasano Crypto Challenges
Go
3
star
38

ghetto-life-stream

Parses items for a Google Buzz feed from various sources.
PHP
2
star
39

teamcity-client

Team City HTTP client.
Ruby
2
star
40

sydjango-damm

Code for my SyDjango talk "Django Admin: The Missing Manual"
Python
2
star
41

jquery-squeezebox

Replacement for jquery.ui.accordion to avoid dealing with jquery.ui theming.
JavaScript
2
star
42

cmdsvr

Toy web application server
Python
1
star
43

lime

JavaScript framework, predates jQuery
JavaScript
1
star
44

gedit-ftp-browser

FTP plugin for Gedit
Python
1
star