A
A
Andrew2020-02-15 14:51:45
Django
Andrew, 2020-02-15 14:51:45

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/'


html files have path to static files
{% 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>


Dockerfile:
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


The files are in the docker container
[email protected]:/code/static# ls
admin  css  django_tables2  gis  js  leaflet  leaflet-groupedlayers  leaflet-routing


And here is what is written in the console after the request
[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


Already tried many variations of paths to static files.
Tell me, pliz, where did I make a mistake and what path to point to static files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-02-15
@fugro

runserver is only for development, normally it can only pull up admin statics, the simplest solution is to specify the path not in STATIC_ROOT, but in the list at STATICFILES_DIRS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question