trant trum
trant trum

Reputation: 219

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!

Upvotes: 0

Views: 106

Answers (1)

Paulo Bu
Paulo Bu

Reputation: 29794

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!

Upvotes: 2

Related Questions