xxxxxxxxxx
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
xxxxxxxxxx
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
xxxxxxxxxx
{% load static %}
<img src="{% static 'my_app/example.jpg' %}" alt="My image">
xxxxxxxxxx
{% load static %}
<img src="{% static "my_app/example.jpg" %}" alt="My image">
xxxxxxxxxx
#In your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE.
{% load static %}
<img src="{% static 'my_app/example.jpg' %}" alt="My image">
xxxxxxxxxx
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
xxxxxxxxxx
STATIC_URL is the URL location of static files located in STATIC_ROOT
STATICFILES_DIRS tells Django where to look for static files in a Django project, such as a top-level static folder
STATIC_ROOT is the folder location of static files when collectstatic is run
STATICFILES_STORAGE is the file storage engine used when collecting static files with the collectstatic command.