3

I am following this guide on deploying a django app to AWS Elastic Beanstalk : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

After running eb open, the css for the admin site does not render. It works when running the development server at 127.0.0.1:8000/admin but not when deployed to EB.

I have followed this guidance but it is still not working Elastic Beanstalk does not load the Django admin static files

Can someone explain why this is happening?

Peter Parker
  • 43
  • 1
  • 6

2 Answers2

6

You can create a .ebextension/djnago.config in your project root dir. And code for loading static assests is below:

option_settings:
  aws:elasticbeanstalk:environment:proxy:staticfiles:
    /static: static

I used this for django 4.0 on Amazon Linux 2

Manoj Kumar
  • 440
  • 1
  • 4
  • 21
0

For Amazon Linux 2 you should add the aws:elasticbeanstalk:environment:proxy:staticfiles option setting to your .ebextension configs. Don't forget to run migrate and collect static commands.

container_commands:
  01_migrate:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate"
    leader_only: true

  02_collectstatic:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic"
    leader_only: true

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: ebdjango.settings
  aws:elasticbeanstalk:environment:proxy:staticfiles:
    /static: static

This should work for this setup in your settings.py file

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = '/static/'
B Gam
  • 113
  • 1
  • 6