Python django.core.urlresolvers 模块,set_urlconf() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用django.core.urlresolvers.set_urlconf()

项目:django-sanic-adaptor    作者:ashleysommer    | 项目源码 | 文件源码
def async_get_response_dj_1_10(self, request):
        """This is the get_response function copied directly from Django 1.10.0"""
        """With the addition of async compatibility"""
        """Return an HttpResponse object for the given HttpRequest."""
        # Setup default url resolver for this thread
        set_urlconf(settings.ROOT_URLCONF)

        response = self._middleware_chain(request)
        if isawaitable(response):
            response = await response
        try:
            # Apply response middleware, regardless of the response
            for middleware_method in self._response_middleware:
                response = middleware_method(request, response)
                if isawaitable(response):
                    response = await response
                # Complain if the response middleware returned None (a common error).
                if response is None:
                    raise ValueError(
                        "%s.process_response didn't return an "
                        "HttpResponse object. It returned None instead."
                        % (middleware_method.__self__.__class__.__name__))
        except Exception:  # Any exception should be gathered and handled
            signals.got_request_exception.send(sender=self.__class__, request=request)
            response = self.handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

        response._closable_objects.append(request)

        # If the exception handler returns a TemplateResponse that has not
        # been rendered, force it to be rendered.
        if not getattr(response, 'is_rendered', True) and callable(getattr(response, 'render', None)):
            response = response.render()
            if isawaitable(response):
                response = await response

        if response.status_code == 404:
            logger.warning(
                'Not Found: %s', request.path,
                extra={'status_code': 404, 'request': request},
            )

        return response