MCPcopy
hub / github.com/django/django / request

Method request

django/test/client.py:1067–1112  ·  view source on GitHub ↗

Make a generic request. Compose the environment dictionary and pass to the handler, return the result of the handler. Assume defaults for the query environment, which can be overridden using the arguments to the request.

(self, **request)

Source from the content-addressed store, hash-verified

1065 self.headers = None
1066
1067 def request(self, **request):
1068 """
1069 Make a generic request. Compose the environment dictionary and pass
1070 to the handler, return the result of the handler. Assume defaults for
1071 the query environment, which can be overridden using the arguments to
1072 the request.
1073 """
1074 environ = self._base_environ(**request)
1075
1076 # Curry a data dictionary into an instance of the template renderer
1077 # callback function.
1078 data = {}
1079 on_template_render = partial(store_rendered_templates, data)
1080 signal_uid = "template-render-%s" % id(request)
1081 signals.template_rendered.connect(on_template_render, dispatch_uid=signal_uid)
1082 # Capture exceptions created by the handler.
1083 exception_uid = "request-exception-%s" % id(request)
1084 got_request_exception.connect(self.store_exc_info, dispatch_uid=exception_uid)
1085 try:
1086 response = self.handler(environ)
1087 finally:
1088 signals.template_rendered.disconnect(dispatch_uid=signal_uid)
1089 got_request_exception.disconnect(dispatch_uid=exception_uid)
1090 # Check for signaled exceptions.
1091 self.check_exception(response)
1092 # Save the client and request that stimulated the response.
1093 response.client = self
1094 response.request = request
1095 # Add any rendered template detail to the response.
1096 response.templates = data.get("templates", [])
1097 response.context = data.get("context")
1098 response.json = partial(self._parse_json, response)
1099 # Attach the ResolverMatch instance to the response.
1100 urlconf = getattr(response.wsgi_request, "urlconf", None)
1101 response.resolver_match = SimpleLazyObject(
1102 lambda: resolve(request["PATH_INFO"], urlconf=urlconf),
1103 )
1104 # Flatten a single context. Not really necessary anymore thanks to the
1105 # __getattr__ flattening in ContextList, but has some edge case
1106 # backwards compatibility implications.
1107 if response.context and len(response.context) == 1:
1108 response.context = response.context[0]
1109 # Update persistent cookie data.
1110 if response.cookies:
1111 self.cookies.update(response.cookies)
1112 return response
1113
1114 def get(
1115 self,

Calls 9

SimpleLazyObjectClass · 0.90
resolveFunction · 0.90
_base_environMethod · 0.80
handlerMethod · 0.80
check_exceptionMethod · 0.80
connectMethod · 0.45
disconnectMethod · 0.45
getMethod · 0.45
updateMethod · 0.45