简体   繁体   English

Django视图/模板框

[英]Django view/template boxes

I am new to python/django (came from PHP) and there is a design problem i have no idea how to solve. 我是python / django(来自PHP)的新手,有一个设计问题,我不知道如何解决。

Let's say we have main content block and some side column. 假设我们有主要的内容块和一些侧栏。 Side column displayed at each page of website. 网站的每个页面上都会显示侧栏。 But boxes can differ(same set, but in some pages particular boxes disabled) Side column has several boxes, like news, events, last anything , user details, statistics, etc. Dynamic data. 但是框可以不同(设置相同,但是在某些页面中禁用了特定框)侧栏有几个框,例如新闻,事件,最后的东西 ,用户详细信息,统计信息等。动态数据。

As well as i understand view function should fill context and invoke content.html (this renders main content block) 以及我理解视图功能应填充上下文并调用content.html(这将呈现主要内容块)

While context.html should extend base.html and that base.html has side column inside it. 虽然context.html应该扩展base.html,并且base.html里面有边栏。

The question is: How i pass all this data to side boxes(i am reminding, dynamic data connected to some models)? 问题是:我如何将所有这些数据传递到边箱(我提醒一下,动态数据已连接到某些型号)? I hope someone can explain this to me. 我希望有人可以向我解释。 Thanks in advance 提前致谢

Hi and welcome to Django. 嗨,欢迎来到Django。 The data in the context is available to all blocks. 上下文中的数据可用于所有块。 You don't have to do anything specific to pass context data to a block or an include. 您无需执行任何特定操作即可将上下文数据传递到块或包含。

Additionally, there are template tags that you can use to encapsulate other functionality that you might need at the template level: http://docs.djangoproject.com/en/1.3/howto/custom-template-tags/ 此外,还有一些模板标记可用于封装在模板级别可能需要的其他功能: http : //docs.djangoproject.com/en/1.3/howto/custom-template-tags/

After some additional research i found out, that there is 4 ways to do what i want 经过一些额外的研究,我发现有4种方法可以做我想做的事

1) Middleware 1)中间件
2) Context proccessors 2)上下文处理程序
3) Inclusion tags(template tags), as Brendon mentioned. 3)包含标记(模板标记),如布伦登提到的。
4) django-blocks 4)django块

I stopped on third approach. 我停止了第三种方法。 Tested first three. 经过测试的前三个。

Decided to start blog, to write down own notes... 决定开始写博客,写下自己的笔记...
More detailed review of this approaches: 此方法的详细说明:
http://tigra-potd.blogspot.com/2011/04/django-sidebar-boxesblocksmodules.html http://tigra-potd.blogspot.com/2011/04/django-sidebar-boxesblocksmodules.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM