Ticket #10326: handlerXXX_callable.2.diff
File handlerXXX_callable.2.diff, 4.4 KB (added by , 16 years ago) |
---|
-
django/core/urlresolvers.py
216 216 217 217 def _resolve_special(self, view_type): 218 218 callback = getattr(self.urlconf_module, 'handler%s' % view_type) 219 mod_name, func_name = get_mod_func(callback)220 219 try: 221 return get attr(import_module(mod_name), func_name), {}220 return get_callable(callback), {} 222 221 except (ImportError, AttributeError), e: 223 222 raise ViewDoesNotExist, "Tried %s. Error was: %s" % (callback, str(e)) 224 223 -
tests/regressiontests/urlpatterns_reverse/tests.py
142 142 res = redirect('/foo/') 143 143 self.assertEqual(res['Location'], '/foo/') 144 144 res = redirect('http://example.com/') 145 self.assertEqual(res['Location'], 'http://example.com/') 146 No newline at end of file 145 self.assertEqual(res['Location'], 'http://example.com/') 146 147 148 class HandlerResolutionTests(TestCase): 149 def setUp(self): 150 from django.core.urlresolvers import RegexURLResolver 151 urlconf = 'regressiontests.urlpatterns_reverse.urls_handlers' 152 urlconf_callables = 'regressiontests.urlpatterns_reverse.urls_handlers_callable' 153 self.resolver = RegexURLResolver(r'^$', urlconf) 154 self.callable_resolver = RegexURLResolver(r'^$', urlconf_callables) 155 156 def testNamedHandlers(self): 157 from views import empty_view 158 handler = (empty_view, {}) 159 self.assertEqual(self.resolver.resolve404(), handler) 160 self.assertEqual(self.resolver.resolve500(), handler) 161 162 def testCallableHandlers(self): 163 from views import empty_view 164 handler = (empty_view, {}) 165 self.assertEqual(self.callable_resolver.resolve404(), handler) 166 self.assertEqual(self.callable_resolver.resolve500(), handler) -
tests/regressiontests/urlpatterns_reverse/urls_handlers_callable.py
1 from django.conf.urls.defaults import patterns 2 from views import empty_view 3 4 urlpatterns = patterns('') 5 6 handler404 = empty_view 7 handler500 = empty_view -
tests/regressiontests/urlpatterns_reverse/urls_handlers.py
1 from django.conf.urls.defaults import patterns 2 3 urlpatterns = patterns('') 4 5 handler404 = 'regressiontests.urlpatterns_reverse.views.empty_view' 6 handler500 = 'regressiontests.urlpatterns_reverse.views.empty_view' -
docs/topics/http/urls.txt
244 244 handler404 245 245 ---------- 246 246 247 A string representing the full Python import path to the view that should be248 called if none of the URL patterns match.247 A callable, or a string representing the full Python import path to the view 248 that should be called if none of the URL patterns match. 249 249 250 250 By default, this is ``'django.views.defaults.page_not_found'``. That default 251 251 value should suffice. 252 252 253 .. versionchanged:: 1.2 254 Previous versions of Django only accepted strings representing import paths. 255 253 256 handler500 254 257 ---------- 255 258 256 A string representing the full Python import path to the view that should be257 called in case of server errors. Server errors happen when you have runtime 258 errors in view code.259 A callable, or a string representing the full Python import path to the view 260 that should be called in case of server errors. Server errors happen when you 261 have runtime errors in view code. 259 262 260 263 By default, this is ``'django.views.defaults.server_error'``. That default 261 264 value should suffice. 262 265 266 .. versionchanged:: 1.2 267 Previous versions of Django only accepted strings representing import paths. 268 263 269 include 264 270 ------- 265 271