2017-09-14 03:24:12 +08:00
|
|
|
from django.urls import RegexURLPattern, RegexURLResolver, include
|
2017-01-28 05:13:40 +08:00
|
|
|
from django.views import defaults
|
2011-09-12 06:36:16 +08:00
|
|
|
|
2015-08-17 22:45:00 +08:00
|
|
|
__all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'url']
|
2011-09-12 06:36:16 +08:00
|
|
|
|
2017-01-28 05:13:40 +08:00
|
|
|
handler400 = defaults.bad_request
|
|
|
|
handler403 = defaults.permission_denied
|
|
|
|
handler404 = defaults.page_not_found
|
|
|
|
handler500 = defaults.server_error
|
2011-09-12 06:36:16 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2015-08-17 23:07:03 +08:00
|
|
|
def url(regex, view, kwargs=None, name=None):
|
2013-10-25 01:30:03 +08:00
|
|
|
if isinstance(view, (list, tuple)):
|
2011-09-12 06:36:16 +08:00
|
|
|
# For include(...) processing.
|
|
|
|
urlconf_module, app_name, namespace = view
|
|
|
|
return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
|
2015-08-18 01:45:07 +08:00
|
|
|
elif callable(view):
|
2011-09-12 06:36:16 +08:00
|
|
|
return RegexURLPattern(regex, view, kwargs, name)
|
2015-08-18 01:45:07 +08:00
|
|
|
else:
|
|
|
|
raise TypeError('view must be a callable or a list/tuple in the case of include().')
|