Re-usable HTML code / widgets

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:13:35

问题


Sometimes I need to use the same html code in different templates, like:

<div class="mylist"><span>item-1</span><span>item-2</span>...</div>

or more complicated widgets. I'm new to Django so I want to learn what do you usually do in these kinds of situations? Do you create your own template tags or what?


回答1:


It sounds like you're after an inclusion tag, http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags .

An inclusion tag is a very simple type of template tag for breaking out markup and code into other templates. This should fit the bill for your example.

You can write more complicated template tags to do pretty much anything else you need if you need to eventually, but inclusion tags are a good place to start.



来源:https://stackoverflow.com/questions/3447158/re-usable-html-code-widgets

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