Skip to content
Browse files

Fixed #18225 -- Staticfiles template tag does not fail silently

static template tag now returns an empty string if the file was not found.
  • Loading branch information...
1 parent 435081f commit 878a601e1c82326853ca9c29cd6cb3bcb88e6670 @MoritzS MoritzS committed
View
5 django/contrib/staticfiles/templatetags/staticfiles.py
@@ -10,4 +10,7 @@ def static(path):
A template tag that returns the URL to a file
using staticfiles' storage backend
"""
- return staticfiles_storage.url(path)
+ try:
+ return staticfiles_storage.url(path)
+ except ValueError:
+ return ''
View
0 tests/regressiontests/static_templatetag/__init__.py
No changes.
View
0 tests/regressiontests/static_templatetag/models.py
No changes.
View
8 tests/regressiontests/static_templatetag/tests.py
@@ -0,0 +1,8 @@
+from django.template import Template
+from django.test import TestCase
+
+class StaticTemplatetagTest(TestCase):
+
+ def test_staticfile_does_not_exist(self):
+ t=Template('{% load staticfiles %}{% static "file/does/not.exist" %}')
+ self.assertEqual(t.render(), '')

0 comments on commit 878a601

Please sign in to comment.
Something went wrong with that request. Please try again.