简体   繁体   中英

Can django template tags and inclusion tags have little HTML in them?

I am writing custom template tags and inclusion tags for my project. Both of those files have few HTML tags in them. Like "<br>" etc. So I was wondering if it is against django practices to have HTML tags in those two files? Thanks in advance!

In my opinion, including HTML code inside template tags will tight-couple the logic of the tag with the output content so you maybe won't be able to re-use it in other contexts. This is what strictly best practices dictates.

Sometimes is useful to look aside and just break this rules to achieve nice solutions. It hardly depends on context.

My suggestion is, try to figure out a way where you can refactor the logic into the tag without needing to include the HTML. If you find it, great! If not, take the shot and include it.

It is a very wide opinion oriented question. I hope mine will help a little.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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