Skip to content

Commit

Permalink
Fixed #19392 -- Improved error for old-style url tags with dashes.
Browse files Browse the repository at this point in the history
Thanks dloewenherz for the report.
  • Loading branch information
aaugustin committed Dec 9, 2012
1 parent 8248d14 commit 4951932
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion django/template/defaulttags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,12 @@ def url(parser, token):
if len(bits) < 2:
raise TemplateSyntaxError("'%s' takes at least one argument"
" (path to a view)" % bits[0])
viewname = parser.compile_filter(bits[1])
try:
viewname = parser.compile_filter(bits[1])
except TemplateSyntaxError as exc:
exc.args = (exc.args[0] + ". "
"The syntax of 'url' changed in Django 1.5, see the docs."),
raise
args = []
kwargs = {}
asvar = None
Expand Down
8 changes: 7 additions & 1 deletion tests/regressiontests/templates/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,20 @@ def test_url_reverse_no_settings_module(self):
with self.assertRaises(urlresolvers.NoReverseMatch):
t.render(c)

def test_url_explicit_exception_for_old_syntax(self):
def test_url_explicit_exception_for_old_syntax_at_run_time(self):
# Regression test for #19280
t = Template('{% url path.to.view %}') # not quoted = old syntax
c = Context()
with self.assertRaisesRegexp(urlresolvers.NoReverseMatch,
"The syntax changed in Django 1.5, see the docs."):
t.render(c)

def test_url_explicit_exception_for_old_syntax_at_compile_time(self):
# Regression test for #19392
with self.assertRaisesRegexp(template.TemplateSyntaxError,
"The syntax of 'url' changed in Django 1.5, see the docs."):
t = Template('{% url my-view %}') # not a variable = old syntax

@override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
def test_no_wrapped_exception(self):
"""
Expand Down

0 comments on commit 4951932

Please sign in to comment.