Django执行顺序 [英] Django order of execution

查看:174
本文介绍了Django执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

django在接收到请求时执行各种组件的顺序是什么?具体来说,与路由解析的功能相比,中间件是否被调用?上下文处理器何时被调用?

In what order does django execute the various components when it receives a request? Specifically when does the middleware get invoked compared to the function that a route resolves to? And when do context processors get called?

谢谢

推荐答案

在视图之前和返回响应时执行中间件。
渲染模板时,通常在视图结尾处执行上下文处理器。

The middlewares are executed before the view and when returning the response. The context processor is executed when rendering a template, usually at the end of the view.

所以:

(请求) - >中间件,从上到下 - >视图 - > context_processor - >(响应) - >中间件,从下到上

(request) -> middleware, from top to bottom -> view -> context_processor -> (response) -> middleware, from bottom to top

这篇关于Django执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆