Django-2

in url definition file, there always some text like
urlpatterns = patterns('',
    url(r'^archive/$', 'mysite.views.archive', {'blogid': 3}),
    url(r'^about/$', 'mysite.views.about', {'blogid': 3}),
)


the {'blogid':3}  is the third parameter

def url(regex, view, kwargs=None, name=None, prefix=''):


and further pass into return object

RegexURLPattern(regex, view, kwargs, name)


then it will be the default_args of

class RegexURLPattern(LocaleRegexProvider):
    def __init__(self, regex, callback, default_args=None, name=None):
        LocaleRegexProvider.__init__(self, regex)


 

then in get_response function, it will retrieve the value as **callback_kwargs

response = callback(request, *callback_args, **callback_kwargs)

 

 

 
 

=================================

In setting.spy, if we set DEBUG to False , we must set  ALLOWED_HOSTS  to a valid server. Otherwise 500 error will return .

=================================

When raise Http404   in view function definition,   what will happen?

URL resolover will call , with view_type is 404,  self.urlconf_module  is urls.py under proejct

    def _resolve_special(self, view_type):
        callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
        if not callback:
            # No handler specified in file; use default
            # Lazy import, since django.urls imports this file
            from django.conf import urls
            callback = getattr(urls, 'handler%s' % view_type)
        return get_callable(callback), {}

so if  urls.py has no definition of  'handler404',  it will search  'django.conf.urls', and the module has function 

django.views.defaults.page_not_found   as handler, with default template name  404.html

==========

if we define  such function in urls.py under project

def handler404(*args, **kwargs):
    pass

the code will go to here, instead of default function mentioned above


 the system also has a function named def handle_uncaught_exception(self, request, resolver, exc_info):

it will also try to find 500 error handler like 404 mentioned above

你可能感兴趣的:(Django-2)