Created
June 29, 2018 15:15
-
-
Save tadeo/c88ac1f6a482c65fbebe8961c6bc97f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
from django.conf import settings | |
register = template.Library() | |
@register.simple_tag(takes_context=True) | |
def absolutize_path(context, *args): | |
relative_url = ''.join(args) | |
absolute_paths = context.get('absolute_paths', False) | |
if absolute_paths: | |
if relative_url.startswith('/'): | |
relative_url = relative_url[1:] | |
return '{}/{}'.format(settings.APPS_DIR, relative_url) | |
else: | |
return relative_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it in templates as:
if you pass
absolute_paths=True
in the context the output will be the absolute file system path as/app/app_name/static/js/project.js
, else you will get the standard/static/js/project.js