0
0
Djangoframework~5 mins

Static files in templates in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of static files in Django templates?
Static files are used to add styles, images, and scripts to web pages. They make the page look good and interactive.
Click to reveal answer
beginner
How do you load static files in a Django template?
You add {% load static %} at the top of the template to tell Django you want to use static files.
Click to reveal answer
beginner
How do you reference a CSS file named 'style.css' located in the static folder inside a Django template?
Use <link href="{% static 'style.css' %}" rel="stylesheet"> inside the <head> section.
Click to reveal answer
intermediate
Why should you use the {% static %} template tag instead of hardcoding file paths?
Because {% static %} automatically finds the correct path to static files, even if you change settings or deploy to another server.
Click to reveal answer
beginner
Where do you place static files in a Django project by default?
Static files go inside a folder named 'static' within your app or project directory.
Click to reveal answer
Which template tag do you use to load static files in Django templates?
A{% load static %}
B{% static load %}
C{% load files %}
D{% static %}
How do you correctly reference an image named 'logo.png' in a Django template?
A<img src="{% load static 'logo.png' %}">
B<img src="logo.png">
C<img src="/static/logo.png">
D<img src="{% static 'logo.png' %}">
Where should you put your CSS files in a Django project to use them as static files?
AInside the static folder
BInside the templates folder
CInside the media folder
DInside the migrations folder
What happens if you forget to add {% load static %} in your template but use {% static %} tag?
AThe static files load normally
BYou get a template error
CThe page loads but without styles
DDjango automatically adds the load tag
Why is it better to use {% static %} instead of hardcoding '/static/' in URLs?
AIt makes the code longer
BIt is slower to load files
CIt helps Django find files even if static URL changes
DIt only works in development
Explain how to include a static CSS file in a Django template from start to finish.
Think about where the file goes, what you load, and how you reference it.
You got /3 concepts.
    Describe why using the {% static %} tag is important when working with static files in Django templates.
    Consider what happens if you move your project or change settings.
    You got /4 concepts.