Question

I want to have a block oh html across all my templates (like a sidebar for basic form submissions), which is easily implemented on the html files by using blocks.

However, my doubt is not about the repetitions across templates, but across views. Since the functionality will be the same across all templates, it would be really boring (and bad programming) to define the request handling (that would come from that side bar's submissions) for every view I have! How should I handle this? Should (and can) I make a view dedicated to handling that "all-around" part of the template?

Any advices are welcome,

Thanks in advance

No correct solution

OTHER TIPS

Daniel is refering to an Inclusion Tag

Basically, a custom template tag is used for scenarios like yours (... code reusability amongs many other advantages)

Also this post might be helpful: Django Custom Inclusion Tags

Another approach could be using template inheritance - create a base template, which defines the layout, and override the blocks of code that would change for specific views.

Here is an example of template inheritance: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance

Use a custom template tag - probably an inclusion tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top