liveBook · Manning

Static resource directory

As explained in Django in Action

A static directory is a filesystem directory containing files that a web application serves as static assets.

A static resource directory stores files a web application serves unchanged: images, CSS, and JavaScript. In Django, the project-level static directory is the tidy cupboard for these assets, even though production may deploy them somewhere else. section 7.3

Set up a simple Django static directory like this:

  • Place an asset such as logo.png in static/img. section 7.3
  • Keep images, JavaScript, and CSS in separate subdirectories so the directory does not become an asset junk drawer. section 7.3

Templates use Django’s static tag to turn a path relative to the static directory into a URL. Load the tag library, then write {% static 'img/logo.png' %} inside an HTML image or link tag. The browser requests that URL, and Django’s development server serves the matching file. section 7.3

RiffMates home page

With logo.png in RiffMates/static/img, home.html loads the static tag library and displays the logo. The same page can link to the application’s named routes, while base.html adds a Home link to the navigation.

How Django in Action covers it

How deep it goes
Explains directory creation, settings configuration, template resolution, and development serving, while deferring production deployment steps.
Examples
Uses the RiffMates logo, home page template, image subdirectory, and favicon redirect as concrete assets.
What it assumes
Assumes basic Django templates and settings, while introducing static-tag loading and asset-directory configuration.
What you can do after
Operate/configure Django to store assets, expose their URLs, and reference them from templates.
How it connects
Connects Django templates, static files, URL routing, HTML image and link tags, and favicons.

Also explained in

Compare how 2 books explain static resource directory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.