Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Closed
wants to merge 1 commit into from

2 participants

Moritz Sichert Jannis Leidel
Moritz Sichert
MoritzS commented May 02, 2012

static template tag now returns an empty string if the file was not found.

Moritz Sichert Fixed #18225 -- Staticfiles template tag does not fail silently
static template tag now returns an empty string if the file was not found.
878a601
Jannis Leidel jezdez closed this May 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 02, 2012
Moritz Sichert Fixed #18225 -- Staticfiles template tag does not fail silently
static template tag now returns an empty string if the file was not found.
878a601
This page is out of date. Refresh to see the latest.
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(), '')
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.