I have deployed my site to Elastic Beanstalk. And it seems My assets are not loading. If I do some work arounds found from stackoverflow I get into a weird situation. If admin assets load, then site assets are gone and vice-versa.
I am using Django 4.0.1, with Nginx server on Amazon Linux 2.
I tried to reload page many times, disabled browser cache from dev tools in chrome.
Also I get 404 for assets on site using above config in settings.py but admin assets are working.
Are you doing your “collectstatic” after deplying the code? Does the web server have the appropriate permissions to that directory? What does your nginx configuration look like for your /static/ path?
I have a post-deploy platform hook which runs, collectstatic:
if [[ "$EB_IS_COMMAND_LEADER" == "true" ]]; then
python manage.py migrate --noinput
python manage.py createsu
python manage.py collectstatic --noinput --clear
fi
I confirm from logs from EC2 instance, its executing without error.
I haven’t created any nginx config for beanstalk. Do I need one? I am assuming it works out of the box.
I wouldn’t know. I don’t know what it’s configuration is or how it’s running your application.
But by running collectstatic, you’re replicating your static files into BASE_DIR/static/. Since you’re doing this in order to allow nginx to serve those files directly (rather than having Django do it), I’m assuming some configuration would be required.
I have gone through like 200 stackoverflow threads and atleast 200+ google searched websites. I have same results and no one mentioned to change nginx. So I am assuming Something is wrong on django side.
What is your local configuration?
Are you using nginx? (If not, what webserver are you using?)
Are you running your Django app within uwsgi? (If not, what app server are you using?)
What are the specific directory structures involved? (Both for your app and your destination for your static files.)
Have you read and configured your environment according to the deployment docs referenced previously?
Also, do they work at all under any combination of configurations? (Most importantly, is it working if you’re just running this using runserver?) There is a possibility that you don’t have your staticfiles app configured correctly or that you’re not referring to the right urls for those files.