Answer the question
In order to leave comments, you need to log in
Django how to set up the return of images from local storage?
How can I make the server return an image when requesting the /static/file.png route?
Answer the question
In order to leave comments, you need to log in
It remains only to bring the default nginx config for Django :
server {
listen 80;
server_name domain.ltd;
root /srv/app/public;
# Logs.
access_log /var/log/nginx/domain.ltd_access.log;
error_log /var/log/nginx/domain.ltd_error.log;
# Options.
client_max_body_size 0;
keepalive_timeout 5;
# Locations.
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_pass http://127.0.0.1:8001; # See guniconf.py file.
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
}
/srv/app/
├── example
│ ├── forms.py
│ ├── __init__.py
│ ├── migrations
│ ├── models.py
│ ├── settings.py
│ ├── static
│ ├── templates
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
├── logs
├── manage.py
├── public
│ └── static
├── README.md
├── requirements.txt
└── venv
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'public', 'static')
STATIC_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'public', 'media')
/srv/app/
├── example
├── logs
├── public
│ ├── media
│ └── static
└── manage.py
STATIC_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'media')
/srv/app/
├── example
├── logs
├── media
├── public
│ └── static
└── manage.py
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question