Как включить staticfiles в проект wsgi django?

Сегодня я столкнулся с проблемой подключения статических файлов к моему проекту.

Если я запускаю приложение django с командой: python manage.py runserver <ip>:<port> то статические файлы найдены. Если я запускаю приложение django как wsgi сервис (systemctl start myapp), я получаю ошибку, что статические файлы не найдены.

Мой проект в /home/alevt/health_check. У меня следующая структура проекта:

---- client
-------- manage.py
-------- my.ini
-------- app
------------ urls.py
------------ settings.py
------------ wsgi.py
-------- health_app
------------ urls.py
------------ static
--------------- scripts
----------------- myscript.js
------------ templates
--------------- index.html

settings.py

INSTALLED_APPS = [ ...
'django.contrib.staticfiles',
'health_app',
...]
 
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

index.html

{% load static %}
<script src="{% static 'scripts/myscript.js' %}"></script>

ERROR

Not Found: /static/scripts/myscript.js

my.ini

[uwsgi]
http = 10.107.14.161:8000
module=app.wsgi:application
chdir = /home/alevt/health_check/client/
wsgi-file = /home/alevt/health_check/client/app/wsgi.py
virtualenv=/home/alevt/health_check/env
single-interpreter = true
enable-threads = true
master = true

И мое служебное досье

Description=uWSGI instance to serve myproject
 
[Service]
ExecStart=/usr/bin/bash -c 'uwsgi --ini /home/alevt/health_check/client/my.ini'
KillSignal=SIGQUIT
Type=notify
 
[Install]
WantedBy=multi-user.target```

Попробуйте это:

 STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'health_app/static/')
)

my.ini файл:

static = /health_app/static
Вернуться на верх