Question

I would like to ask a question about django base templates. How do they exactly work..What do I mean.

I have a base file that lets say has a static conten and a block content that changes in templates that extend the base file.

base.html

<html>
    <head>
        <script src="main.js"></script>
    </head>
    <body>
        <div class="side-nav">
            <!--static content here-->
        </div>
        <div class="content">
            {% block "content"%} {%endblock%}
        </div>
    </body>
</html>

I have three templates that extend base.html, e.g t1.html, t2.html and t3.html. All of them have some dom elements that are edited by the main.js file importedn in base.html. My question is the following. Does it load all the page its time i render a template and thus main.js is run again or does it only render the "dynamic" content of the base file? Will the code of main.js run everytime I load a template that extends base.html?

Was it helpful?

Solution

You basically have to understand a basic difference:

Rendering in done on the Server Side

JavaScript works on Clent side.

So if JS is sent again to Client side than it will definitely run again

You can read more about Templates in Django here : https://docs.djangoproject.com/en/1.5/topics/templates/

OTHER TIPS

Django put together all templates at first. After that completed page will be send to browser. Your javascript code run in browser with full page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top