Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS Flask Basics Templates and Static Files Static Files

matthias papsdorf
PLUS
matthias papsdorf
Courses Plus 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,915 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
PLUS
matthias papsdorf
Courses Plus 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