I am planning to build and deploy a Django site, and I want to understand what I’m doing first (rather than just following a list of instructions). I am confused by what seems to be an internal contradiction in the Django docs about static files. According to Django’s deployment instructions, if I have a simple setup with my Django app and my static files on the same server, I should:
- Push your code up to the deployment server.
- On the server, run
collectstatic
to copy all the static files intoSTATIC_ROOT
.- Configure your web server to serve the files in
STATIC_ROOT
under the URLSTATIC_URL
.
But Django’s instructions about setting STATIC_ROOT seem to include the opposite instructions (in a “warning” box no less), which say this about STATIC_ROOT:
The absolute path to the directory where
collectstatic
will collect static files for deployment.Example:
"/var/www/example.com/static/"
If the staticfiles contrib app is enabled (as in the default project template), the
collectstatic
management command will collect static files into this directory. See the how-to on managing static files for more details about usage.Warning
This should be an initially empty destination directory for collecting your static files from their permanent locations into one directory for ease of deployment; it is not a place to store your static files permanently. You should do that in directories that will be found by staticfiles’s
finders
, which by default, are'static/'
app sub-directories and any directories you include inSTATICFILES_DIRS
.
So I’m confused. According to the warning in this second set of instructions, STATIC_ROOT
“should be an initially empty destination directory for collecting your static files from their permanent locations into one directory for ease of deployment; it is not a place to store your static files permanently.”
But if it’s not a place to store them permanently, why do the deployment instructions (the first set above) tell me to “Configure your web server to serve the files in STATIC_ROOT
”?
I’m just trying to set up a simple one-server deployment, and I just want to know what directories I need to create. I am unable to understand this based on the instructions I am reading. I would greatly appreciate clarification. Thanks!
(PS The forum would only let me post something with two links, so I apologize for the lack of links in the quoted material.)