Using multiple views in one page

Hello. How can I use multiple views in one pages(In one html file)

You don’t.

A view receives a request and returns a response.

In the common case, a view can render a template using a context to build that response.

The view can call multiple functions to obtain data to add to the context.

The template can include multiple templates to render the response.

But overall, it’s just one view being called for the request.

1 Like

you can do this with django and htmx. you can have a view render a template but within that template you can reference many other views via htmx. you can refer bugbytes channel on youtube for the same.

While this will work exactly as you’ve described, it’s still not “one template / multiple views”. Each one of those separate views are going to render their own HTML to augment the existing page. You are not building a page from a single template with content from multiple views.

yes, a good compromise (or a better compromise than) between one view per template or learn a separate frontend like angular, react, vue; then convert your django to rest api with DRF and deploy and maintain them them separately.