1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #17716 -- Prevented include('...', app_name='...') without a namespace.

This commit is contained in:
Tim Graham 2015-02-08 13:44:07 -05:00
parent 34ccb3cc03
commit 27eeb64a96
2 changed files with 12 additions and 1 deletions

View File

@ -17,6 +17,9 @@ handler500 = 'django.views.defaults.server_error'
def include(arg, namespace=None, app_name=None):
if app_name and not namespace:
raise ValueError('Must specify a namespace if specifying app_name.')
if isinstance(arg, tuple):
# callable returning a namespace hint
if namespace:

View File

@ -10,6 +10,7 @@ import unittest
from admin_scripts.tests import AdminScriptTestCase
from django.conf import settings
from django.conf.urls import include
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.core.urlresolvers import (
@ -399,7 +400,7 @@ class ReverseShortcutTests(TestCase):
@ignore_warnings(category=RemovedInDjango20Warning)
def test_reverse_by_path_nested(self):
# Views that are added to urlpatterns using include() should be
# reversible by doted path.
# reversible by dotted path.
self.assertEqual(reverse('urlpatterns_reverse.views.nested_view'), '/includes/nested_path/')
def test_redirect_view_object(self):
@ -749,3 +750,10 @@ class ViewLoadingTests(TestCase):
# swallow it.
self.assertRaises(AttributeError, get_callable,
'urlpatterns_reverse.views_broken.i_am_broken')
class IncludeTests(SimpleTestCase):
def test_include_app_name_but_no_namespace(self):
msg = "Must specify a namespace if specifying app_name."
with self.assertRaisesMessage(ValueError, msg):
include('urls', app_name='bar')