[英]Django: How can I find methods/functions filling in the specific template
Say, I find some bug in a web interface. 说,我在网络界面中发现了一些错误。 I open firebug and discover element and class, id of this element.
我打开firebug并发现元素和类,这个元素的id。 By them I can then identify a template which contains variables, tags and so on.
通过它们,我可以识别包含变量,标签等的模板。 How can I move forward and reveal in which .py files these variables are filled in?
如何向前移动并显示填充这些变量的.py文件?
I know how it works in Lift framework: when you've found a template there are elements with attributes bound to snippets. 我知道它在Lift框架中是如何工作的:当你找到一个模板时,有些元素的属性绑定到片段。 So you can easily proceed to specific snippets and edit code.
因此,您可以轻松地继续使用特定的代码段并编辑代码。
How does it work in django? 它在django中如何运作? May be, I suppose wrong process... then point me to the right algorithm, please.
可能是,我想错误的过程......然后请指出正确的算法。
In well designed django, you should only have to edit the template. 在精心设计的django中,您只需编辑模板即可。 Good design provides clean separation.
良好的设计提供清洁分离。 It's possible the developer may have been forced todo something unusual...but you could try to edit the template and see what happens (make backup 1st)
有可能开发人员可能被迫做了一些不寻常的事情......但你可以尝试编辑模板并看看会发生什么(使备份成为第1个)
Determining template variable resolution is all about Context
. 确定模板变量分辨率完全是关于
Context
。
view
being invoked. view
。 settings.py
for the list of TEMPLATE_CONTEXT_PROCESSORS
. settings.py
以获取TEMPLATE_CONTEXT_PROCESSORS
列表。 These are routines that are called automatically and invisibly to add values to the Context being passed to the template. {%expr%}
that can do evaluation in the template , but I always use it as close to the point of need as possible to highlight the fact it is being used. {%expr%}
的老式django片段,它可以在模板中进行评估,但我总是尽可能地使用它,以突出显示它正在被使用的事实。 Note that because of the way Django template variables are resolved, {{foo.something}}
could be either a value or a callable method. 请注意,由于Django模板变量的解析方式,
{{foo.something}}
可以是值或可调用方法。 I have serious issues with this syntax, but that's the way they wrote it. 我对这种语法有严重的问题,但这就是他们编写它的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.