P
P
pvgdrk2015-04-24 00:30:42
Django
pvgdrk, 2015-04-24 00:30:42

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')

How would calling this function look like on the JS side?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dibrovsd, 2015-04-30
@dibrovsd

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 question

Ask a Question

731 491 924 answers to any question