A production environment would host your static files on another sever. If youâre using AWS or Digital Ocean in production, they have âbucketsâ that your static files will be stored in. Django has a really nice third-party package that works very well with Digital Ocean and AWS static file storage.
Rather than trying to toss ideas out in the abstract, it would probably be more effective to get into the specifics - and this includes understanding the complete details of the environment in which youâre trying to do this, and whatâs going wrong.
For example, you wrote:
What do you mean by this? What specifically is being rendered in the browser?
Also, what is your production environment? Is it self-hosted or service-hosted? What kind of web server are you running? (Apache? nginx?) How is Django itself being run? (uwsgi? gunicorn? something else?) All these factors are interrelated and part of the deployment process is understanding how all the pieces fit together.
Production deployment is a complex issue, with probably hundreds of combinations possible. There are no âstandard generic answersâ that are going to work in every situation.
For example, @Suttonium writes âA production environment would host your static files on another server.â But, I have never worked in that type of environment. Iâve deployed at least a dozen production environments and every single one co-hosts all static and media files on the same device.
It mentions that you can host static files on another server OR on the server that the rest of your code is hosted on, which makes perfect sense, especially because both tactics require the use of the collectstatic function.
Regarding hosting static files and assets on another server (or bucket), here is are some tools I have used to assist with the process in the past and from personal experience, I can say they work like a charm.
Production environment is Ubuntu server with Nginx and Gunicorn. Iâm running multiple Django projects there.
When I added + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) to settings.py and set DEBUG = True then uploaded images in MEDIA were rendered fine, but when I set to DEBUG = False then itâs not server anymore.
What should I do ?
Should I use Nginx to server this folder or something else ?
Another popular option if you donât want to configure Nginx to serve static assets is to use the popular WhiteNoise app. http://whitenoise.evans.io/en/stable/
@KenWhitesell, @mblayman, @Suttonium - thank you for your answers - at the end I found out the solution is just in front of me all the time !!!
When I went to configure my NGINX I found out that I already HAVE the same configuration for static files (so the static files are not just working by itself as I thought - they are working because of this configuration line):
@Ethionline If youâre having an issue that you would like assistance with, I would suggest you open up a new topic thread and post the complete description of the issue.