javascript - Django: How to load a script for every page? -


say want include bootstrap or angular every single page in views, there more elegant way copying same line each file?

you need django template inheritance. include in template base.html, , in there define block filled in children templates:

<html>     <!-- base.html -->     ......     {% block content %}     {% endblock %}     <!-- include js/css here -->     <script type="text/javascipt" src="{{ static_url }}jquery.js">     <link rel="stylesheet" type="text/css" href="mystyle.css"> </html> 

then templates extend base.html , override block content so:

<!-- sub.html --> {% extends "base.html" %} {% block content %}         <!-- current page html goes here --> {% endblock %} 

in way, have included in base.html automatically inherited , available in sub.html.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -