diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index c1ca947..1da6230 100644
a
|
b
|
class URLNode(Node):
|
409 | 409 | url = '' |
410 | 410 | try: |
411 | 411 | url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) |
412 | | except NoReverseMatch as e: |
| 412 | except NoReverseMatch: |
| 413 | exc_info = sys.exc_info() |
413 | 414 | if settings.SETTINGS_MODULE: |
414 | 415 | project_name = settings.SETTINGS_MODULE.split('.')[0] |
415 | 416 | try: |
… |
… |
class URLNode(Node):
|
421 | 422 | # Re-raise the original exception, not the one with |
422 | 423 | # the path relative to the project. This makes a |
423 | 424 | # better error message. |
424 | | raise e |
| 425 | six.reraise(*exc_info) |
425 | 426 | else: |
426 | 427 | if self.asvar is None: |
427 | | raise e |
| 428 | six.reraise(*exc_info) |
428 | 429 | |
429 | 430 | if self.asvar: |
430 | 431 | context[self.asvar] = url |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 02d3460..267d5cc 100644
a
|
b
|
class Templates(TestCase):
|
372 | 372 | with self.assertRaises(urlresolvers.NoReverseMatch): |
373 | 373 | t.render(c) |
374 | 374 | |
| 375 | @override_settings(TEMPLATE_STRING_IF_INVALID='%s is invalid', SETTINGS_MODULE='also_something') |
| 376 | def test_url_reverse_view_name(self): |
| 377 | # Regression test for #19827 |
| 378 | from django.template import Template, Context |
| 379 | |
| 380 | t = Template('{% url will_not_match %}') |
| 381 | c = Context() |
| 382 | try: |
| 383 | t.render(c) |
| 384 | except urlresolvers.NoReverseMatch: |
| 385 | tb = sys.exc_info()[2] |
| 386 | depth = 0 |
| 387 | while tb.tb_next is not None: |
| 388 | tb = tb.tb_next |
| 389 | depth += 1 |
| 390 | self.assertTrue(depth > 5, "The traceback context was lost when reraising the traceback. See #19827") |
| 391 | |
375 | 392 | def test_url_explicit_exception_for_old_syntax_at_run_time(self): |
376 | 393 | # Regression test for #19280 |
377 | 394 | t = Template('{% url path.to.view %}') # not quoted = old syntax |