Skip to content
Django template rendering indirector based on object class
Python
Pull request Compare This branch is 8 commits ahead, 5 commits behind jaylett:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
render_as
.gitignore
LICENSE
README.md
setup.py
test_settings.py

README.md

Django "render_as" template tag

{% render_as obj type %} is a simple template tag that renders a suitable template based on the object passed to it and a type. For Django model objects, the template will be one of:

  • <app>/<model>_<type>.html
  • render_as/default_<type>.html

For non-model objects, the template will be one of:

  • <module>/<class>_<type>.html
  • render_as/default_<type>.html

where <module> is the last component of the module path and <class> will be the lower-cased classname (so for an object whose class is my_library.sub_library.MyClass the first template checked will be sub_library/myclass.html).

With TEMPLATE_DEBUG = True, various template errors will be shown as the template output along with a stack trace in the runserver. Neither appears when running live.

James Aylett http://tartarus.org/james/

Something went wrong with that request. Please try again.