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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -