Skip to content

Loading…

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

Closed
wants to merge 1 commit into from

2 participants

@MoritzS

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

@MoritzS MoritzS Fixed #18225 -- Staticfiles template tag does not fail silently
static template tag now returns an empty string if the file was not found.
878a601
@jezdez jezdez closed this
@MoritzS MoritzS deleted the MoritzS:patch18225 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2012
  1. @MoritzS

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

    MoritzS committed
    static template tag now returns an empty string if the file was not found.
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(), '')
Something went wrong with that request. Please try again.