3

I have deployed my Django app in amazon elastic beanstalk. However, the css in the django admin is not working. I understand that it's a collectstatic issue. This is what my settings.py looks like:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

And I have this line in my ebconfig.config file:

container_commands:
  01_collectstatic:
    command: "python manage.py collectstatic --noinput"

However, this is how it looks like once I deploy it in amazon: enter image description here I have tried seeing the log files in amazon console. I found a line that reads:

EmbeddedPostBuild/postbuild_0_dcape/Command 01_collectstatic] : Starting activity...
.....  
  0 static files copied to '/opt/python/bundle/33/app/static', 102 unmodified.

What do I need to do to make sure it works?

Tom Morris
  • 10,490
  • 32
  • 53
QuestionEverything
  • 4,809
  • 7
  • 42
  • 61

1 Answers1

0

I was having the same issue for the longest time. It seems like you have to tell beanstalk where your static folder will be located on the production server.

In your ebconfig.config where you specify commands/container_commands add an option settings so that beanstalk can know what your static_root equates to on the live server.

This is how I do it:

settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

config file

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: MDGOnline.settings
  "aws:elasticbeanstalk:container:python:staticfiles":
    "static/": "www/static/"

Check out this wonderful AWS Elastic Beanstalk Doc for more detailed info

Yamen Alghrer
  • 651
  • 6
  • 12