Skip to main content

Extension for default template system for making inheritance more flexible. Adding some kind of themes.

Project description

Latest PyPI version Build status

Extension for default template system for making inheritance more flexible. Adding some kind of themes.


Imagine you have several sites on different hosts. They differ by visually and small functional. django-vest this is a way to use one code base for this situation.

He allowing to split templates on themes - one per site. We also have extended inheritance between themes - we have DEFAULT_THEME and we can override each template in CURRENT_THEME. Exmaple:

{% extends 'DEFAULT_THEME/index.html' %}
{% block page_title %}Dark theme{% endblock %}

django-vest have some tools for logic splitting according by CURRENT_THEME in views. Assume we have some form class who is different in each theme. Then our code may looks like:

from django_vest.decorators import themeble

@themeble(name='Form', themes=('dark_theme',))
class DarkThemeForm(object):
    ''' Some kind of logic/fields for dark_theme form
    name = 'DarkThemeForm'

class DefaultForm(object):
    ''' Default logic/fields for all themes
    name = 'Default form'

from .forms import Form

In example bellow Form class will be alias for DarkThemeForm if settings.CURRENT_THEME == 'dark_theme' otherwise it is DefaultForm.

If you want restricting access to views according by CURRENT_THEME just use only_for decorator:

from django.http import Http404
from django.views.generic.base import TemplateView

from django_vest import only_for

def my_view(request):

# Redirect for special page
dark_theme_page = only_for('dark_theme', redirect_to='restict_access')(

# Raise Http404 when user trying to open page with invalid theme
dark_theme_page_not_found = \
    only_for('dark_theme', raise_error=Http404)(

Extends for default templates

Version 0.1.3 has a new template loader django_vest.templates_loaders.AppsLoader and new keyword DJANGO_ORIGIN.

Now we can override default django admin template without copy past of full origin file.


File: templates/main_theme/admin/change_list.html

{% extends "DJANGO_ORIGIN/admin/change_list.html" %}
{% load i18n admin_urls admin_static admin_list %}

{% block breadcrumbs %}
  <div>Template has been overridden</div>
  {{ block.super }}
{% endblock %}


$ pip install django_vest

And add next setting options to your


DEFAULT_THEME = 'main_theme'

# Unique for each host
CURRENT_THEME = 'dark_theme'

Or you can set os environment:


Also you can specify list of backends for getting settings. Default is:

  • django_vest.config.backends.simple - getting settings about theme from project`s settings file.

  • django_vest.config.backends.env - from os envirom

Then you need to update structure of your templates like this:

| - dark_theme
    | - index.html
| - main_theme
    | - index.html

IMPORTANT: theme folder must ends with _theme suffix (example: my_super_mega_theme)

Other config backends (Experimental)

Django-vest have are several other backends like:

django_vest.config.backends.database. If you have some singleton model for store settings of your site you can use django_vest.fields.VestField for storing information of CURRENT_THEME in database.

For activating this feature you must do next steps:

  • Add django_vest.fields.VestField to you settings model and migrate.

  • Add django_vest.config.backends.database backend to top of VEST_SETTINGS_BACKENDS_LIST setting. Example:



  1. Fork the django-vest repo on GitHub.

  2. Clone your fork locally:

$ git clone
  1. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

$ mkvirtualenv django-vest
$ cd django-vest/
$ python develop
  1. Create a branch for local development:

 $ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.
  1. When you’re done making changes, check that your changes pass the tests, including testing other Python versions with tox:

$ make test-all
  1. Commit your changes and push your branch to GitHub:

$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
  1. Submit a pull request through the GitHub website.

Licence & Authors

The MIT License (MIT)

Copyright (c) 2015 Vladimir Savin.

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-vest-0.1.6.tar.gz (9.2 kB view hashes)

Uploaded source

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