Skip to content

Instantly share code, notes, and snippets.

@balazs-endresz
Created September 9, 2015 14:09
Show Gist options
  • Save balazs-endresz/d8fd3d73f591615d0254 to your computer and use it in GitHub Desktop.
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
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