mirror of
				https://github.com/django/django.git
				synced 2025-11-04 05:35:37 +00:00 
			
		
		
		
	Fixed #21530 -- Prevent AttributeError in default URLconf detection code.
Thanks to @dmyerscoug for the report and original patch and to @alasdairnicol for the added tests.
This commit is contained in:
		
							parent
							
								
									ffc0e0ca37
								
							
						
					
					
						commit
						a020dd0a99
					
				
					 4 changed files with 43 additions and 1 deletions
				
			
		| 
						 | 
					@ -483,7 +483,7 @@ def technical_404_response(request, exception):
 | 
				
			||||||
            or (request.path == '/'
 | 
					            or (request.path == '/'
 | 
				
			||||||
                and len(tried) == 1             # default URLconf
 | 
					                and len(tried) == 1             # default URLconf
 | 
				
			||||||
                and len(tried[0]) == 1
 | 
					                and len(tried[0]) == 1
 | 
				
			||||||
                and tried[0][0].app_name == tried[0][0].namespace == 'admin')):
 | 
					                and getattr(tried[0][0], 'app_name', '') == getattr(tried[0][0], 'namespace', '') == 'admin')):
 | 
				
			||||||
            return default_urlconf(request)
 | 
					            return default_urlconf(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
 | 
					    urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										8
									
								
								tests/view_tests/default_urls.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								tests/view_tests/default_urls.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					from django.conf.urls import patterns, include, url
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.contrib import admin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					urlpatterns = patterns('',
 | 
				
			||||||
 | 
					    # This is the same as in the default project template
 | 
				
			||||||
 | 
					    url(r'^admin/', include(admin.site.urls)),
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
							
								
								
									
										5
									
								
								tests/view_tests/regression_21530_urls.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								tests/view_tests/regression_21530_urls.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					from django.conf.urls import patterns, url
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					urlpatterns = patterns('',
 | 
				
			||||||
 | 
					    url(r'^index/$', 'view_tests.views.index_page', name='index'),
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -139,6 +139,35 @@ class DebugViewTests(TestCase):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        self.assertRaises(TemplateDoesNotExist, self.client.get, '/render_no_template/')
 | 
					        self.assertRaises(TemplateDoesNotExist, self.client.get, '/render_no_template/')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @override_settings(ROOT_URLCONF='view_tests.default_urls')
 | 
				
			||||||
 | 
					    def test_default_urlconf_template(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Make sure that the default urlconf template is shown shown instead
 | 
				
			||||||
 | 
					        of the technical 404 page, if the user has not altered their
 | 
				
			||||||
 | 
					        url conf yet.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        response = self.client.get('/')
 | 
				
			||||||
 | 
					        self.assertContains(
 | 
				
			||||||
 | 
					            response,
 | 
				
			||||||
 | 
					            "<h2>Congratulations on your first Django-powered page.</h2>"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @override_settings(ROOT_URLCONF='view_tests.regression_21530_urls')
 | 
				
			||||||
 | 
					    def test_regression_21530(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Regression test for bug #21530.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        If the admin app include is replaced with exactly one url
 | 
				
			||||||
 | 
					        pattern, then the technical 404 template should be displayed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        The bug here was that an AttributeError caused a 500 response.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        response = self.client.get('/')
 | 
				
			||||||
 | 
					        self.assertContains(
 | 
				
			||||||
 | 
					            response,
 | 
				
			||||||
 | 
					            "Page not found <span>(404)</span>",
 | 
				
			||||||
 | 
					            status_code=404
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ExceptionReporterTests(TestCase):
 | 
					class ExceptionReporterTests(TestCase):
 | 
				
			||||||
    rf = RequestFactory()
 | 
					    rf = RequestFactory()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue