How to include staticfiles in wsgi django project?
Today I ran into a problem connecting static files to my project.
If I run django app with command: python manage.py runserver <ip>:<port>then static files are found. If I run the django app as a wsgi service (systemctl start myapp), I get an error that no static files were found.
My project in /home/alevt/health_check. I have next structure of project:
---- 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
And my file of service
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```
Try this:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'health_app/static/')
)
my.ini file:
static = /health_app/static