Home > front end >  Processing Repeated Bootstrap Modals in Django
Processing Repeated Bootstrap Modals in Django

Time:11-11

How do people process bootstrap modals in Django that need to be shown on multiple pages? Do you have a special class to handle a second form? Do you use Crispy Forms?

For example, if I have a Contact Us modal that is launched from a navigation bar on all pages in the application, how would I appropriately process that modal information? I can't imagine copying and pasting the same modal form and view code all over. That's clearly not DRY. I would imagine that there would be a way to do this, since it's a common problem.

CodePudding user response:

Just stick it all in your base.html? Then extend that on all your other templates. Don't understand the issue.

CodePudding user response:

For example, if I have a Contact Us modal that is launched from a navigation bar on all pages in the application, how would I appropriately process that modal information? I can't imagine copying and pasting the same modal form and view code all over.

Consider using an include statement, so you can write your modal in its own template, then 'include' it in the page you wish to have it reused on. Here's an example, and here's a link to the docs:

{% include "app/example-modal.html" %}

You then can create a handler in your views file to parse the any requests from the modal.

  • Related