Best Practice for Context Processors vs. Template Tags?

我是研究僧i 提交于 2019-12-23 07:20:16

问题


In which cases is it better to create template tags (and load them into the template), than creating a context processor (which fills the request automatically)?

e.g. I have a dynamic menu that has to be included into all templates, so I'm putting it into my base.html. What is the preferred usage: context processor or custom template tag? And why?


回答1:


Context processors is for putting data (information, content, objects) into the context used to render page.

Template tags are for formatting or processing that content.

A template tag that makes up new data is confusing. Not impossible or wrong, but very confusing.



来源:https://stackoverflow.com/questions/2791696/best-practice-for-context-processors-vs-template-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!