Best practice including javascript in django template

I used to do this in a template

<html> ... <script> {% include "myapp/includes/jquery-1.7.1.min.js" %} {% include "myapp/includes/myscript.js" %} </script> ... 

But this makes all js code appear on the page source.

I do not use any form in my template, so can I use the Media class to add js?

Should I use <script src=".." or the ref = ".." link to add javascript files? Which one is better?

+6
source share
1 answer

Use <script src="yourscript.js"></script> , as usual, without the include tag.

Django include template tag is not intended to load a JavaScript source. It is used to include a subpattern whose markup can access the context template of the inclusion template. Read here .

+13
source

Source: https://habr.com/ru/post/913241/


All Articles