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++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -