Static files in templates
📖 Scenario: You are building a simple Django web page that needs to show a logo image and apply some styling using CSS.Static files like images and CSS must be properly linked in your HTML templates to display correctly.
🎯 Goal: Create a Django template that correctly loads static files and uses them to display a logo image and apply a CSS style.
📋 What You'll Learn
Create a Django template file named
index.html.Load the static template tag library at the top of the template.
Use the
{% static %} tag to link to a CSS file named styles.css located in the static folder.Use the
{% static %} tag to display an image named logo.png located in the static folder.Add a
link tag to include the CSS file in the template's <head> section.Add an
<img> tag to show the logo image in the <body>.💡 Why This Matters
🌍 Real World
Websites often need to include images, stylesheets, and scripts. Django's static files system helps organize and serve these files efficiently.
💼 Career
Knowing how to properly include and manage static files in Django templates is essential for web developers working with Django to build professional websites.
Progress0 / 4 steps