user3264316
user3264316

Reputation: 332

Django - same html, different views

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

Upvotes: 0

Views: 612

Answers (2)

karthikr
karthikr

Reputation: 99680

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

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 600041

Use a custom template tag - probably an inclusion tag.

Upvotes: 0

Related Questions