Answer the question
In order to leave comments, you need to log in
Django. How to load a block in a template on click?
These are the basics. But after going through the documentation, I didn’t remember (or maybe I didn’t know).
There is a basic template in which Block A is loaded. I need the contents of block B to be loaded into the corresponding {% block blockB %}{% endblock %} when the button is clicked, while the contents of A and all loaded resources are preserved. How to do it?
View will be like this?:
def loadBlockB(request):
return render_to_response('loadBlockB.html')
Answer the question
In order to leave comments, you need to log in
Need
- make a url for ajax request, for example
url(r'^/ajax/loadBlockB/$', view='loadBlockB', name='loadBlockB'),
- In js write
$('#container_id').load( '/ajax/loadBlockB/')
And that's it.
It is assumed that you are using jquery
If not, then any other way to make an ajax request
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question