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): 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): if isinstance(arg, tuple):
# callable returning a namespace hint # callable returning a namespace hint
if namespace: if namespace:

View File

@ -10,6 +10,7 @@ import unittest
from admin_scripts.tests import AdminScriptTestCase from admin_scripts.tests import AdminScriptTestCase
from django.conf import settings from django.conf import settings
from django.conf.urls import include
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.core.urlresolvers import ( from django.core.urlresolvers import (
@ -399,7 +400,7 @@ class ReverseShortcutTests(TestCase):
@ignore_warnings(category=RemovedInDjango20Warning) @ignore_warnings(category=RemovedInDjango20Warning)
def test_reverse_by_path_nested(self): def test_reverse_by_path_nested(self):
# Views that are added to urlpatterns using include() should be # 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/') self.assertEqual(reverse('urlpatterns_reverse.views.nested_view'), '/includes/nested_path/')
def test_redirect_view_object(self): def test_redirect_view_object(self):
@ -749,3 +750,10 @@ class ViewLoadingTests(TestCase):
# swallow it. # swallow it.
self.assertRaises(AttributeError, get_callable, self.assertRaises(AttributeError, get_callable,
'urlpatterns_reverse.views_broken.i_am_broken') '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')