0
I deployed a project Python and Django in the Digitalocean, but I’m having trouble with static files
Inside my project, in the folder static when typing the command pwd to see the full file path, I have the following.
/root/getcode/notafiscal/getcode/static
In settings.py I have:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(APP_ROOT, 'static')
and within /etc/nginx/sites-available/getcode I have the following:
server {
listen 80;
server_name meu_endereco_ip;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /root/getcode/notafiscal/getcode/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
However, when accessing the IP address, my site is all disfigured, as if it had not "read" the folder static.
Note. I did all the installation of the application Django in an MV virtualenv.
In setting.py when trading STATIC_ROOT for
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
and reproduce by python manage.py runserver 0.0.0.0:8000, the site appears perfectly configured when accessing the browser meu_ip:8000
Therefore, I believe the error is in some configuration of the nginx.
How to solve?
Rafael, did check if the folder
staticcontains any files? You even ran the commandpython manage.py collectstaticon the server?– fernandosavio
Yes for both questions. When I start the program with the command
python manage.py runserverit works on the door:8000. I believe there’s some problem with the configuration ofnginx– Rafael
The Static module only serves files when
DEBUG=True, when in production should be configured for Nginx or Apache to serve the folderstatic– fernandosavio
I set up the folder
staticto thenginxas described in the question.– Rafael