{% extends 'template_A.html' %}{# usual html stuffs #}
{% block content %} {# page content stuffs here #} <script type="text/javascript"> // A function targeting a specific area of, only // and Only the template_B.html page, e.g $( ".class" ).addClass( "new-class" ); </script>{% endblock %}
<html>
<head><!-- Head things -->
<script src="jquery-resource"></script>
</head>
<body>
<!-- below snippet coming from template_B.html -->
{% block content %} {# page content stuffs here #} <script type="text/javascript"> // A function targeting a specific area of, only // and Only the template_B.html page, e.g $( ".class" ).addClass( "new-class" ); </script>{% endblock %}</body>
</html>
The browser/client does not get two 'chunks' of HTML, Django renders the entire page first and sends the entire rendered piece at once after rendering both templates.
If you need your JS to be interpreted earlier, add an extra {% block %} to template_A up in the <head> section, and override that block rather than (or in addition to) overriding your content block so that your JS is interpreted before the rest of the body.
-James
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c4106146-0892-4513-bab5-f6c7d18c64a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think the issue here is in how you're loading jQuery. It doesn't seem like jQuery has been loaded successfully. Make sure the path to your jQuery file is correct. This seems more like a client side issue rather than a server side (Django) issue.
When Django sends the HTML response to your browser, it's already in its final form. Meaning both templates A and B has already been rendered and assembled together. All this is done on the server side. The loading and execution of JS files happens on the client side (browser). Since
Django is a server side framework, it isn't concerned about how JS files are loaded on the browser.
--