django-app-namespace-template-loader


Namedjango-app-namespace-template-loader JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://github.com/Fantomas42/django-app-namespace-template-loader
SummaryTemplate loader allowing you to both extend and override a template at the same time.
upload_time2016-06-29 12:26:32
maintainerNone
docs_urlNone
authorFantomas42
requires_pythonNone
licenseBSD License
keywords django template loader
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            ====================================
Django App Namespace Template Loader
====================================

|travis-develop| |coverage-develop|

Provides a template loader that allows you to load a template from a
specific application. This allows you to both **extend** and **override** a
template at the same time.

The default Django loaders require you to copy the entire template you want
to override, even if you only want to override one small block.

This is the issue that this package tries to resolve.

Examples:
---------

You want to change the titles of the admin site, you would originally
created this template: ::

    $ cat my-project/templates/admin/base_site.html
    {% extends "admin/base.html" %}
    {% load i18n %}

    {% block title %}{{ title }} | My Project{% endblock %}

    {% block branding %}
    <h1 id="site-name">My Project</h1>
    {% endblock %}

    {% block nav-global %}{% endblock %}

Extend and override version with a namespace: ::

    $ cat my-project/templates/admin/base_site.html
    {% extends "admin:admin/base_site.html" %}

    {% block title %}{{ title }} - My Project{% endblock %}

    {% block branding %}
    <h1 id="site-name">My Project</h1>
    {% endblock %}

Note that in this version the block ``nav-global`` does not have to be
present because of the inheritance.

Shorter version without namespace: ::

    $ cat my-project/templates/admin/base_site.html
    {% extends ":admin/base_site.html" %}

    {% block title %}{{ title }} - My Project{% endblock %}

    {% block branding %}
    <h1 id="site-name">My Project</h1>
    {% endblock %}

If we do not specify the application namespace, the first matching template
will be used. This is useful when several applications provide the same
templates but with different features.

Example of multiple empty namespaces: ::

    $ cat my-project/application/templates/application/template.html
    {% block content%}
    <p>Application</p>
    {% endblock content%}

    $ cat my-project/application_extension/templates/application/template.html
    {% extends ":application/template.html" %}
    {% block content%}
    {{ block.super }}
    <p>Application extension</p>
    {% endblock content%}

    $ cat my-project/templates/application/template.html
    {% extends ":application/template.html" %}
    {% block content%}
    {{ block.super }}
    <p>Application project</p>
    {% endblock content%}

Will render: ::

    <p>Application</p>
    <p>Application extension</p>
    <p>Application project</p>

Installation
------------

First of all install ``django-app-namespace-template-loader`` with your
favorite package manager. Example : ::

    $ pip install django-app-namespace-template-loader

Once installed, add ``app_namespace.Loader`` to the ``TEMPLATE_LOADERS``
setting of your project. ::

    TEMPLATE_LOADERS = [
      'app_namespace.Loader',
      ... # Other template loaders
    ]

With Django >= 1.8 ``app_namespace.Loader`` should be added to the
``'loaders'`` section in the OPTIONS dict of the ``DjangoTemplates`` backend
instead. ::

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'OPTIONS': {
                'loaders': [
                    'app_namespace.Loader',
                    'django.template.loaders.filesystem.Loader',
                    'django.template.loaders.app_directories.Loader',
                ],
            },
        },
    ]

Note: With Django 1.8, ``app_namespace.Loader`` should be first in the list
of loaders.

Known limitations
=================

``app_namespace.Loader`` can not work properly if you use it in conjunction
with ``django.template.loaders.cached.Loader`` and inheritance based on
empty namespaces.

Notes
-----

Based originally on: http://djangosnippets.org/snippets/1376/

Requires: Django >= 1.8

Tested with Python 2.7, 3.3, 3.4.

If you want to use this application for previous versions of Django, use the
version 0.3.1 of the package.

If you want to use this application with Python 2.6, use the version 0.2 of
the package.

.. |travis-develop| image:: https://travis-ci.org/Fantomas42/django-app-namespace-template-loader.png?branch=develop
   :alt: Build Status - develop branch
   :target: http://travis-ci.org/Fantomas42/django-app-namespace-template-loader
.. |coverage-develop| image:: https://coveralls.io/repos/Fantomas42/django-app-namespace-template-loader/badge.png?branch=develop
   :alt: Coverage of the code
   :target: https://coveralls.io/r/Fantomas42/django-app-namespace-template-loader
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Fantomas42/django-app-namespace-template-loader",
    "name": "django-app-namespace-template-loader",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "django,template,loader",
    "author": "Fantomas42",
    "author_email": "fantomas42@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e6/5d/c7ce27fbb1cf4fc14c6726d2c96d4072903678cbc047fd3bd524c7310658/django-app-namespace-template-loader-0.4.1.tar.gz",
    "platform": "any",
    "description": "====================================\nDjango App Namespace Template Loader\n====================================\n\n|travis-develop| |coverage-develop|\n\nProvides a template loader that allows you to load a template from a\nspecific application. This allows you to both **extend** and **override** a\ntemplate at the same time.\n\nThe default Django loaders require you to copy the entire template you want\nto override, even if you only want to override one small block.\n\nThis is the issue that this package tries to resolve.\n\nExamples:\n---------\n\nYou want to change the titles of the admin site, you would originally\ncreated this template: ::\n\n    $ cat my-project/templates/admin/base_site.html\n    {% extends \"admin/base.html\" %}\n    {% load i18n %}\n\n    {% block title %}{{ title }} | My Project{% endblock %}\n\n    {% block branding %}\n    <h1 id=\"site-name\">My Project</h1>\n    {% endblock %}\n\n    {% block nav-global %}{% endblock %}\n\nExtend and override version with a namespace: ::\n\n    $ cat my-project/templates/admin/base_site.html\n    {% extends \"admin:admin/base_site.html\" %}\n\n    {% block title %}{{ title }} - My Project{% endblock %}\n\n    {% block branding %}\n    <h1 id=\"site-name\">My Project</h1>\n    {% endblock %}\n\nNote that in this version the block ``nav-global`` does not have to be\npresent because of the inheritance.\n\nShorter version without namespace: ::\n\n    $ cat my-project/templates/admin/base_site.html\n    {% extends \":admin/base_site.html\" %}\n\n    {% block title %}{{ title }} - My Project{% endblock %}\n\n    {% block branding %}\n    <h1 id=\"site-name\">My Project</h1>\n    {% endblock %}\n\nIf we do not specify the application namespace, the first matching template\nwill be used. This is useful when several applications provide the same\ntemplates but with different features.\n\nExample of multiple empty namespaces: ::\n\n    $ cat my-project/application/templates/application/template.html\n    {% block content%}\n    <p>Application</p>\n    {% endblock content%}\n\n    $ cat my-project/application_extension/templates/application/template.html\n    {% extends \":application/template.html\" %}\n    {% block content%}\n    {{ block.super }}\n    <p>Application extension</p>\n    {% endblock content%}\n\n    $ cat my-project/templates/application/template.html\n    {% extends \":application/template.html\" %}\n    {% block content%}\n    {{ block.super }}\n    <p>Application project</p>\n    {% endblock content%}\n\nWill render: ::\n\n    <p>Application</p>\n    <p>Application extension</p>\n    <p>Application project</p>\n\nInstallation\n------------\n\nFirst of all install ``django-app-namespace-template-loader`` with your\nfavorite package manager. Example : ::\n\n    $ pip install django-app-namespace-template-loader\n\nOnce installed, add ``app_namespace.Loader`` to the ``TEMPLATE_LOADERS``\nsetting of your project. ::\n\n    TEMPLATE_LOADERS = [\n      'app_namespace.Loader',\n      ... # Other template loaders\n    ]\n\nWith Django >= 1.8 ``app_namespace.Loader`` should be added to the\n``'loaders'`` section in the OPTIONS dict of the ``DjangoTemplates`` backend\ninstead. ::\n\n    TEMPLATES = [\n        {\n            'BACKEND': 'django.template.backends.django.DjangoTemplates',\n            'OPTIONS': {\n                'loaders': [\n                    'app_namespace.Loader',\n                    'django.template.loaders.filesystem.Loader',\n                    'django.template.loaders.app_directories.Loader',\n                ],\n            },\n        },\n    ]\n\nNote: With Django 1.8, ``app_namespace.Loader`` should be first in the list\nof loaders.\n\nKnown limitations\n=================\n\n``app_namespace.Loader`` can not work properly if you use it in conjunction\nwith ``django.template.loaders.cached.Loader`` and inheritance based on\nempty namespaces.\n\nNotes\n-----\n\nBased originally on: http://djangosnippets.org/snippets/1376/\n\nRequires: Django >= 1.8\n\nTested with Python 2.7, 3.3, 3.4.\n\nIf you want to use this application for previous versions of Django, use the\nversion 0.3.1 of the package.\n\nIf you want to use this application with Python 2.6, use the version 0.2 of\nthe package.\n\n.. |travis-develop| image:: https://travis-ci.org/Fantomas42/django-app-namespace-template-loader.png?branch=develop\n   :alt: Build Status - develop branch\n   :target: http://travis-ci.org/Fantomas42/django-app-namespace-template-loader\n.. |coverage-develop| image:: https://coveralls.io/repos/Fantomas42/django-app-namespace-template-loader/badge.png?branch=develop\n   :alt: Coverage of the code\n   :target: https://coveralls.io/r/Fantomas42/django-app-namespace-template-loader",
    "bugtrack_url": null,
    "license": "BSD License",
    "summary": "Template loader allowing you to both extend and override a template at the same time.",
    "version": "0.4.1",
    "split_keywords": [
        "django",
        "template",
        "loader"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "d8a9e6ae192e5c66dc0f83fa521a0fc5",
                "sha256": "356539413b5d1de0eff91aea7a03806b5ef6874ee5420ea8c273f72bbc601d74"
            },
            "downloads": -1,
            "filename": "django_app_namespace_template_loader-0.4.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d8a9e6ae192e5c66dc0f83fa521a0fc5",
            "packagetype": "bdist_wheel",
            "python_version": "2.7",
            "requires_python": null,
            "size": 15080,
            "upload_time": "2016-06-29T12:26:37",
            "upload_time_iso_8601": "2016-06-29T12:26:37.244148Z",
            "url": "https://files.pythonhosted.org/packages/2e/a6/0a5ee33c8d0468b8e3aa8eca0c48dc1ecc5701adce63780b87cdf2df8e41/django_app_namespace_template_loader-0.4.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "51532ae302b46b380beed6bfd920cbce",
                "sha256": "7a450985479a2e07fe8a1e4e8208fc9e1d8b35503526dd28eba5f8ad4ba31d4e"
            },
            "downloads": -1,
            "filename": "django-app-namespace-template-loader-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "51532ae302b46b380beed6bfd920cbce",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13889,
            "upload_time": "2016-06-29T12:26:32",
            "upload_time_iso_8601": "2016-06-29T12:26:32.588811Z",
            "url": "https://files.pythonhosted.org/packages/e6/5d/c7ce27fbb1cf4fc14c6726d2c96d4072903678cbc047fd3bd524c7310658/django-app-namespace-template-loader-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2016-06-29 12:26:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Fantomas42",
    "github_project": "django-app-namespace-template-loader",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "lcname": "django-app-namespace-template-loader"
}
        
Elapsed time: 0.01236s