[Django]-Why won't elastic beanstalk render css for the django admin site?

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

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

Leave a comment