Displaying another template with a click button in Django
I have the following template files in my django project:
- base.html
- base_test1.html
- base_test2.html
Here and base_test1.html
, and base_test2.html
extends base.html
. My home page displays base_test1.html
. On my home page, I have a button that should display when clicked base_test2.html
. How can I achieve this?
I am trying to use jQuery ajax call so that when a button is clicked, I call the corresponding view in views.py
my application. But that doesn't seem to work as the ajax call just returns the html page per request, rather than executing it.
source to share
- Create another url, look at the second template I think you did.
- Make it a button as a link to this URL. Thus, when the button is clicked, the page with the second template is displayed.
Should base_test2.html
n't return full HTML page if you want to use ajax . But only some block in the html page that you replace in the original page.
source to share