- April 23, 2007
- template tag media simple_tag
- 9 (after 9 ratings)
A slightly improved version of snippet #195 which keeps the logic but makes use of the
simple_tag decorator to drastically simplify the code.
For an alternative to this sort of tag, check out the media context processor in my template_utils app.
1 2 3 4 5 6 7 8 9 10 11 12
from django.conf import settings from django.template import Library def media_path(path): import urlparse import os.path if os.path.exists(os.path.join(settings.MEDIA_ROOT, path)): return urlparse.urljoin(settings.MEDIA_URL, path) return '' register = Library() register.simple_tag(media_path)
More like this
- Mod to allow simple_tag to access context by leaf 6 years, 6 months ago
- twitter_status by zodman 6 years, 7 months ago
- a simple tag with context by dsblank 5 years, 3 months ago
- Git media cache busting tag by adamlofts 5 years, 4 months ago
- inclusion tag with template as variable by forgems 6 years, 1 month ago