Answer the question
In order to leave comments, you need to log in
What is the path to static files in django?
I'm building my django project into a docker container. But static files are not located on the prescribed path.
Before running the command python manage.py runserver
, I execute the command python manage.py collectstatic
All static files are collected in the static folder at the root of the project. I checked that they really are there by logging into the docker container via bash.
Here is the settings.py code
# из этих папок собираются файлы в STATIC_ROOT
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'firstapp', 'static'),
os.path.join(BASE_DIR, 'secondapp', 'static'),
os.path.join(BASE_DIR, 'thirdapp', 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# доступ к файлам по урл
STATIC_URL = '/static/'
{% load static %}
{% load leaflet_tags %}
{% leaflet_css %}
{% leaflet_js %}
<link rel="stylesheet" type="text/css" href="{% static 'leaflet-groupedlayers/leaflet.groupedlayercontrol.min.css' %}">
<script type="text/javascript" src="{% static 'leaflet-groupedlayers/leaflet.groupedlayercontrol.min.js' %}"></script>
RUN mkdir /code/static
COPY . /code/
WORKDIR /code
RUN python manage.py collectstatic --no-input --clear
CMD python /code/manage.py runserver 0.0.0.0:8080
[email protected]:/code/static# ls
admin css django_tables2 gis js leaflet leaflet-groupedlayers leaflet-routing
[15/Feb/2020 10:58:11] "GET /calc/ HTTP/1.1" 200 14586
[15/Feb/2020 10:58:11] "GET /static/leaflet/leaflet.js HTTP/1.1" 404 77
[15/Feb/2020 10:58:11] "GET /static/leaflet/leaflet.extras.js HTTP/1.1" 404 77
[15/Feb/2020 10:58:11] "GET /static/leaflet/leaflet.css HTTP/1.1" 404 77
[15/Feb/2020 10:58:12] "GET /static/leaflet/leaflet.extras.js HTTP/1.1" 404 77
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question