Created
September 9, 2015 14:09
-
-
Save balazs-endresz/d8fd3d73f591615d0254 to your computer and use it in GitHub Desktop.
django-libsass static() function that raises exception if the file doesn't exists
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
import ast | |
from django.templatetags.static import static as django_static | |
def strict_static(path): | |
""" | |
A stricter version of the static() function provided by django-libass: | |
https://github.com/torchbox/django-libsass#custom-functions | |
Raises an exception if a file is not found. Not for production use. | |
""" | |
from django.contrib.staticfiles.finders import find | |
if not find(path): | |
print "Static file not found: %s" % path | |
raise Exception("\n\nStatic file not found: %s" % ast.literal_eval("'%s'" % path)) | |
return '"{}"'.format(django_static(path)) | |
# override the static function provided by django-libsass | |
LIBSASS_CUSTOM_FUNCTIONS = { | |
'static': strict_static, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment