13👍
Django is built to be an “application server”, not a “web server”.
In other words, serving static files from Django will have worse performance than using Apache or Nginx. These static content servers are (1) written in C and (2) optimized for performance.
In contrast, Django is (1) written in pure Python and (2) optimized for developing an application.
See the documentation.
That may be totally fine. I have used Django to serve static content in production, when I knew the load would not be high and I wasn’t serving large files. It depends on what kind of environment “production” actually is.
FYI, A common production setup would be to use Nignx, Django, Gunicorn, and Supervisor. Nginx servers the static content from disk and reverse proxies the rest of it to Gunicorn, which runs multiple Django instances. Supervisor monitors Gunicorn and makes sure it stays running. It all depends on what level of web application you need.
3👍
It is not recommended to serve static files from the django server itself. The recommended way is to serve them in a separate server. check static files deployment, there you will find all you need.
- Got AttributeError when attempting to get a value for field on serializer
- Django conditional Subquery aggregate
- Get a queryset's current order_by ordering
0👍
Extending @Paul Draper’s answer:
When using Nginx, make sure to list the following configuration:
location /media/ {
root path/to/your/media;
}
- How can i access the model instance used by a form from a template?
- Docker env variables not set while log via shell
- Do RESTful service parameters have to be discoverable?
0👍
I used the tutorial for the google section of the django-storages package and it solves the issue serving the files (either static or media or both) from Google Storage, which avoids the trouble of additional configuration on Nginx or the like
- Django's HttpResponseRedirect is http instead of https
- Unsupported lookup 'istartwith' for CharField or join on the field not permitted
- How to build a REST client frontend for a REST API backend?