Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 878a601e1c82326853ca9c29cd6cb3bcb88e6670 1 parent 435081f
Moritz Sichert authored May 02, 2012
5  django/contrib/staticfiles/templatetags/staticfiles.py
@@ -10,4 +10,7 @@ def static(path):
10 10
     A template tag that returns the URL to a file
11 11
     using staticfiles' storage backend
12 12
     """
13  
-    return staticfiles_storage.url(path)
  13
+    try:
  14
+        return staticfiles_storage.url(path)
  15
+    except ValueError:
  16
+        return ''
0  tests/regressiontests/static_templatetag/__init__.py
No changes.
0  tests/regressiontests/static_templatetag/models.py
No changes.
8  tests/regressiontests/static_templatetag/tests.py
... ...
@@ -0,0 +1,8 @@
  1
+from django.template import Template
  2
+from django.test import TestCase
  3
+
  4
+class StaticTemplatetagTest(TestCase):
  5
+
  6
+    def test_staticfile_does_not_exist(self):
  7
+        t=Template('{% load staticfiles %}{% static "file/does/not.exist" %}')
  8
+        self.assertEqual(t.render(), '')

0 notes on commit 878a601

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