BoumTAC
BoumTAC

Reputation: 3781

django how to update template without loading

I would like to update my block content without loading all the page. I think I have to use ajax but I have 2 problems.
How to send the template in Json in Django?
How to change change the template using javascript/jquery I think I have to hide my last template and put my new one but I think there is a better way.

<!DOCTYPE html>
<head>
  <title>{% block title %}{% endblock %}</title>
</head>
<body>

{% block content %}{% endblock %}

</body>
</html>

Upvotes: 0

Views: 305

Answers (1)

catavaran
catavaran

Reputation: 45575

The simplest way to change the part of the html page is to use the .load() method of jQuery:

<div id="content">{% block content %}{% endblock %}</div>

<script>
    $("#content").load("{% url 'page_with_a_new_content' %} #content");
</script>

Upvotes: 2

Related Questions