Static Files in Templates
A snippet showing how to load static files in Django templates.
# models.py
from django.db import models
class Branding(models.Model):
logo_path = models.CharField(max_length=200, default="images/logo.png")
theme_css = models.CharField(max_length=200, default="css/theme.css")
def __str__(self):
return "Branding"
# admin.py
from django.contrib import admin
from .models import Branding
@admin.register(Branding)
class BrandingAdmin(admin.ModelAdmin):
list_display = ("logo_path", "theme_css")
# templates/base.html
<{% load static %}>
<link rel="stylesheet" href="{% static branding.theme_css %}">
<img src="{% static branding.logo_path %}" alt="Logo">
Explanation:
-
Load the static tag with
<{% load static %}>at the top of templates. -
Build URLs with
<{% static 'path/to/file' %}>or from variables.
- Category Templates
- Total Views 1230
- Last Modified 25 January, 2026
- Tags #templates #static #files #css-js
Previous snippet
Escaping Variables in Templates
Next snippet