September 12, 2007
One thing I absolutely love about Django’s template loading
Is the ability to specify a series of template folders in your settings file.
Here’s what we do at work:
1 2 3 4 | TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), "templates"), os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "ANOTHERSITE", "templates")), ) |
It allows us to easily share templates from ANOTHERSITE with sister/sub sites, but when/if you need to override them you just drop your new template your site’s templates folder and you’re off to the races.
Another template tip
If you use the tip above, I’d recommend putting templates that are explicity shared in a templates/shared folder.
Then you can do things like:
1 2 | <!-- filename: templates/base_somethingorother.html -->
{% extends 'shared/shared_somethingorother.html' %} |
It’s a minor tip, but it helps prevent collisions and alerts developers that these templates shouldn’t have any site specific code in them.
Next: Facebook + AIM = evil
Previous: My duh moment – Django and it’s lack of strip filter
Related
- Django Template Development review
- Django testing tip: don’t test template output
- Setup Django with mod_wsgi on your Mac