STATICFILES and the static Tag
Organize and reference your assets.
STATICFILES and the static Tag is a free Django Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Static Files Are
Your CSS, JavaScript, and design images do not change per request. Django calls these static files and serves them separately from your Python views. 🎨
The static App
Django ships django.contrib.staticfiles in INSTALLED_APPS by default. It finds, collects, and serves your assets so you do not wire that up by hand.
INSTALLED_APPS = [
'django.contrib.staticfiles',
]Where Files Live
By convention you keep an app's assets inside a folder named static right next to its views and templates. Django scans every app for that folder.
blog/
static/
blog/
style.cssNamespace Your Folder
Nest assets under a folder matching the app name, like static/blog/. This namespacing stops two apps from clobbering each other's style.css.
The STATIC_URL Setting
The STATIC_URL setting is the public path prefix browsers use to fetch assets. Requests starting with this prefix are routed to your static files.
STATIC_URL = '/static/'Load the static Tag
To reference assets in a template, first load the tag library with load static at the very top of the file.
{% load static %}Use the static Tag
The static tag turns a relative asset path into the correct full URL, so you never hardcode STATIC_URL into your HTML.
<link rel="stylesheet" href="{% static 'blog/style.css' %}">Why Not Hardcode
If you wrote /static/blog/style.css by hand, changing STATIC_URL later would break every page. The static tag keeps your links flexible. ✅
Linking JavaScript
The same static tag works for any asset type. Point a script tag at a JS file and Django resolves the path for you.
<script src="{% static 'blog/app.js' %}"></script>STATICFILES_DIRS
For project-wide assets that belong to no single app, add their folders to STATICFILES_DIRS and Django will search there too.
STATICFILES_DIRS = [BASE_DIR / 'assets']Finders Do the Work
Behind the scenes, static finders walk every app's static folder plus STATICFILES_DIRS to locate the file a template asks for.
Quick Check
Let us check how you reference a static file in a template.
Recap
You learned that static files are your CSS and JS, that they live in namespaced static folders, and that the static tag builds their URLs cleanly. 🎉
Frequently asked questions
Is the “STATICFILES and the static Tag” lesson free?
Yes — the full text of “STATICFILES and the static Tag” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “STATICFILES and the static Tag”?
Organize and reference your assets. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “STATICFILES and the static Tag” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- STATICFILES and the static Tag
- collectstatic for Production
- MEDIA_ROOT and File Uploads
- ImageField and Serving Uploads