开发者

Re-usable HTML code / widgets

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜