CSS Flask Basics Templates and Static Files Static Files

matthias papsdorf
PRO
matthias papsdorf
Pro Student 4,152 Points

defining the scripts block in index.html?

Hey there,

I was just wondering. Since I want to define my blocks in my layout.html, wouldn't it be "better" to have: {% block scripts %} <script src="/static/scripts.js"></script> {% endblock %} in the layout file and then just use: {% block scripts %}{{ super() }}{% endblock %} in the index html?

I am just not sure what the right convention would be in this case

2 Answers

Anthony Attard
Anthony Attard
43,913 Points

Using {% block scripts %} <script src="/static/scripts.js"> {% endblock %} in the layout file and then using {% block scripts %}{{ super() }}{% endblock %} in the index html is a bad idea because it does not let you use a different script on another page. Doing it the way it's done in the video allows you to have different script files in each template.

matthias papsdorf
PRO
matthias papsdorf
Pro Student 4,152 Points

Thank you for the explanation. For some reason I was too fixated on the aspect of having everything in the layout file. It did not think that far that other pages will require other scripts.

cheers, Matthias