django static javascript files

Background

Websites generally need to serve additional files such as images, JavaScript, or CSS. In Django, we refer to these files as “static files”. Django provides django.contrib.staticfiles to help you manage them.

Typical use

Usually the settings file will have:

STATIC_URL = '/static/'

You can then use the following in your template:

{% load static %}
<img src="{% static "my_app/example.jpg" %}" alt="My image">

Which serves up the file off of :

my_app/static/my_app/example.jpg.

Cuauhtemoc Almost 6 years ago