1π
The development server knows how to serve static files but you have to set some settings for this to work in production. You can read about it here.
That will also point you to this page.
You need to do the following:
- Make sure that
django.contrib.staticfiles
is included in yourINSTALLED_APPS
. - In your settings file, define
STATIC_URL
. - Use the
static
template tag to build the URL for the given relative path. For example:
{% load static %}
<img src="{% static "my_app/example.jpg" %}" alt="My image"/>
- Store your static files in a folder called static in your app. For example
my_app/static/my_app/example.jpg
. - Set the
STATICFILES_DIRS
setting in your settings file. For example:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/var/www/static/',
]
π€Eric Bulloch
Source:stackexchange.com