Collectstatic configuration error when deploying Django website on to Heroku and S3
Question: I am trying to deploy my Django website onto Heroku and Amazon S3. However,
after I typed `git push heroku master`, I got this:

    
    
    Counting objects: 3, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 298 bytes | 0 bytes/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    remote: -----> Python app detected
    remote: -----> Installing dependencies with pip
    remote: 
    remote: -----> Preparing static assets
    remote:        Collectstatic configuration error. To debug, run:
    remote:        $ heroku run python ./manage.py collectstatic --noinput**
    remote: 
    remote: -----> Discovering process types
    remote:        Procfile declares types -> web
    remote: 
    remote: -----> Compressing... done, 52.0MB
    remote: -----> Launching... done, v9
    remote:        https://article-django.herokuapp.com/ deployed to Heroku
    remote: 
    remote: Verifying deploy... done.
    To https://git.heroku.com/article-django.git
       4514a97..070a1af  master -> master
    

I type in `heroku run python ./manage.py collectstatic --noinput` and I get
this log:

    
    
    Running `python ./manage.py collectstatic --noinput` attached to terminal... up, run.4058
    /app/static/
    Traceback (most recent call last):
      File "./manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
        settings.INSTALLED_APPS
      File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
        self._setup(name)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
        self._wrapped = Settings(settings_module)
       File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 94, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "/app/django_test/settings.py", line 142, in <module>
    AWS_STORAGE_BUCKET_NAME = os.environ['article-deanna']
      File "/app/.heroku/python/lib/python2.7/UserDict.py", line 23, in   __getitem__
        raise KeyError(key)
    KeyError: 'article-deanna'
    

'article-deanna' is the name of my `AWS_STORAGE_BUCKET_NAME`, as specified in
this snippet in settings.py:

    
    
    try:
        from local_settings import *
    except Exception as e:
        print e.message 
    
    if not DEBUG:
        AWS_STORAGE_BUCKET_NAME = os.environ['article-deanna']
        AWS_ACCESS_KEY_ID = os.environ['(censored)']
        STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
        DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
        S3_URL = 'http://%s.s3.amazonaws.com/assets/' % article-deanna 
        STATIC_URL = S3_URL
    

I also have my Procfile:

    
    
    web: gunicorn django_test.wsgi
    

And this snippet of the script `activate`:

    
    
    # added for S3 deployment
    export AWS_STORAGE_BUCKET_NAME=article-deanna
    export AWS_ACCESS_KEY_ID=(censored)
    export AWS_SECRET_ACCESS_KEY=(censored)
    

I have the correct `AWS_STORAGE_BUCKET_NAME`, so why doesn't Heroku realize
that?


Answer: I think you has to get the env var from name not from value.

here you set "article-deanna" to the variable **AWS_STORAGE_BUCKET_NAME**

`export AWS_STORAGE_BUCKET_NAME='article-deanna'`

and here you has to get the variable back

`AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']`

