I am wondering the reason why Django does not serve the statifiles in production, when DEGUB = False
.
STATICFILES_DIRS
We specify STATICFILES_DIRS
to tell Django where to look for staticfiles that are tied up to a specified app.
STATIC_ROOT
We specify STATIC_ROOT
to tell Django where to store the files once we run python manage.py collectstatic
, so everystatic file is stored in the path specified in STATIC_ROOT
.
Assume that we set STATIC_ROOT = "staticfiles/"
.
This means that once we run the collectstatic command, all the files that are inside STATICFILES_DIRS
paths are going to be stored in "staticfiles/"
STATIC_URL
Finally we specify STATIC_URL
as "prefix" to tell Djando where to look for staticfiles, for example in the HTML <link>
tag, the url that we see is based on STATIC_URL
value
When we upload our project to the server, we upload the entire project, so every single file. Why can't Django serve staticfiles itself when running on server?
As I just said, we upload the entire folder, so the files we uploaded are there (and the staticfiles too!).
QUESTIONS
- I am just wondering, why do we have to specify the staticfiles based on server in production, when Django could do everything for us as it have always done in localhost?
- Isn't load the files from another storage so much slower than load them from main folder of the project?