Heroku push rejected (Django app) - django

I'm deploying a Django app to GitHub and Heroku.
I have deployed it first to GitHub, removing (putting it in the .gitignore file) "settings.py", and now that I'm trying to push it to Heroku, I get an error:
ImportError: No module named settings
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote:
remote: ! Push rejected, failed to compile Python app
How can I avoid to push some file to GitHub, but at the same having the possibility to pushing it to Heroku?
UPDATE:
I've tried to keep settings.py and temp_settings.py separate, but now the app doesn't work anymore. That's the traceback when I try to run the local server:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/stefano/projects/blog-project/blogproject/settings.py", line 104, in <module>
DATABASES['default'].update(db_from_env)
NameError: name 'DATABASES' is not defined
It seems settings.py can't "reach" temp_settings.py, as I've cut-paste all of the database settings in temp_settings. Is that wrong?

The common practice is not to ignore settings.py file from your code base. Instead, do something like:
try:
from temp_settings import *
except ImportError:
pass
at the end of settings.py file and add temp_settings.py to .gitignore
For the credentials that you need to keep private, use temp_settings.

Related

Heroku - Set Procfile to run a Django Command to create DB

I'm deploying my DjangoApp to Heroku.
I'm following all the documentation but not sure how to set the Procfile to run my command, as I do locally to create my shop_peru DB:
This is what I do locally to create the Peru DB:
python manage.py ubigeo_peru
This is my Procfile:
release: python manage.py makemigrations
release: python manage.py migrate
release: python manage.py ubigeo_peru
web: gunicorn stickers_gallito.wsgi --log-file -
ubigeo_peru.py:
import pandas as pd
import csv
from shop.models import Peru
from django.core.management.base import BaseCommand
tmp_data=pd.read_csv('static/data/ubigeo-peru-2018-12-25.csv',sep=',', encoding="utf-8")
class Command(BaseCommand):
def handle(self, **options):
products = [
Peru(
departamento=row['departamento'],
provincia=row['provincia'],
distrito=row['distrito'],
)
for idx, row in tmp_data.iterrows()
]
Peru.objects.bulk_create(products)
When deplying to heroku I get this error:
Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 795 bytes | 795.00 KiB/s, done.
Total 8 (delta 6), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: ! Python has released a security update! Please consider upgrading to python-3.6.8
remote: Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing requirements with pip
remote:
remote: -----> $ python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 204, in fetch_command
remote: app_name = commands[subcommand]
remote: KeyError: 'collectstatic'
remote: During handling of the above exception, another exception occurred:
remote: Traceback (most recent call last):
remote: File "manage.py", line 15, in <module>
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 211, in fetch_command
remote: settings.INSTALLED_APPS
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
remote: self._setup(name)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
remote: self._wrapped = Settings(settings_module)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
remote: mod = importlib.import_module(self.SETTINGS_MODULE)
remote: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote: return _bootstrap._gcd_import(name[level:], package, level)
remote: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
remote: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
remote: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
remote: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
remote: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
remote: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
remote: File "/tmp/build_1d164976f07d1b5308e0df603fc5a5c0/stickers_gallito/settings.py", line 2, in <module>
remote: import django_heroku
remote: ModuleNotFoundError: No module named 'django_heroku'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to stickers-gallito-app.
remote:
To https://git.heroku.com/stickers-gallito-app.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/stickers-gallito-app.git'
(stickers_gallito_env) ogonzales#ogonzales:~/Desktop/web_proyects/stickers_gallito$ git push heroku master
Counting objects: 12, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 1.07 KiB | 1.07 MiB/s, done.
Total 12 (delta 9), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: ! Python has released a security update! Please consider upgrading to python-3.6.8
remote: Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing requirements with pip
remote:
remote: -----> $ python manage.py collectstatic --noinput
remote: 167 static files copied to '/tmp/build_48b84f7db1a8a5df5eb464b11621fa61/staticfiles', 67 unmodified, 278 post-processed.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> release, web
remote:
remote: -----> Compressing...
remote: Done: 115.8M
remote: -----> Launching...
remote: ! Release command declared: this new release will not be available until the command succeeds.
remote: Released v17
remote: https://stickers-gallito-app.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
remote: Running release command...
remote:
remote: Traceback (most recent call last):
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
remote: return self.cursor.execute(sql, params)
remote: psycopg2.ProgrammingError: relation "shop_peru" does not exist
remote: LINE 1: INSERT INTO "shop_peru" ("departamento", "provincia", "distr...
remote: ^
remote:
remote:
remote: The above exception was the direct cause of the following exception:
remote:
remote: Traceback (most recent call last):
remote: File "manage.py", line 15, in <module>
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
remote: self.execute(*args, **cmd_options)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
remote: output = self.handle(*args, **options)
remote: File "/app/shop/management/commands/ubigeo_peru.py", line 22, in handle
remote: Peru.objects.bulk_create(products)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
remote: return getattr(self.get_queryset(), name)(*args, **kwargs)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 465, in bulk_create
remote: ids = self._batched_insert(objs_without_pk, fields, batch_size)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 1149, in _batched_insert
remote: inserted_id = self._insert(item, fields=fields, using=self.db, return_id=True)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 1136, in _insert
remote: return query.get_compiler(using=using).execute_sql(return_id)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1289, in execute_sql
remote: cursor.execute(sql, params)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
remote: return super().execute(sql, params)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
remote: return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
remote: return executor(sql, params, many, context)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
remote: return self.cursor.execute(sql, params)
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
remote: raise dj_exc_value.with_traceback(traceback) from exc_value
remote: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
remote: return self.cursor.execute(sql, params)
remote: django.db.utils.ProgrammingError: relation "shop_peru" does not exist
remote: LINE 1: INSERT INTO "shop_peru" ("departamento", "provincia", "distr...
remote: ^
remote:
remote: Waiting for release.... failed.
To https://git.heroku.com/stickers-gallito-app.git
ab60b75..16f4a2f master -> master
Structure:
stickers_gallito (project)
|_shop (app)
|_management
|_commands
|_ubigeo_peru.py
Settings:
WSGI_APPLICATION = 'stickers_gallito.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'ddl7v8vi4kdkip',
'USER': 'u6sic8t2nrdejq',
'PASSWORD': 'p72e949360dda1614aabf9a51b531d0c4a5f06ecc7e6528e8454f81687b7a321d',
'HOST': 'ec2-54-157-94-8.compute-1.amazonaws.com',
'PORT': '5432',
}
}
You cannot use sqlite database in Heroku. Use on of the databases they provide.
I generally use postgresql
heroku addons:create heroku-postgresql:hobby-dev
This will create an empty database for you
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# add this
import dj_database_url
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
This is will change the database in your setting.py

OSError: [Errno 2] No such file or directory: '/tmp/MakeCalls/Static'

When doing 'git push heroku master' (from a Django app), the push gets rejected. I've included the traceback below. I can disable the collectstatic but then all the static files are missing from the webpage.
When I run python manage.py collectstatic --noinput on my localserver it does not give any errors. I've spent the past two days on this, not sure what I'm doing wrong. I've included my .settings below for the staticfiles. I am using whitenoise which works perfectly fine on my localhost.
I think it has to do with a relative path that is not found. But that can't be it because there are no errors on my local server?
remote: $ python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "manage.py", line 10, in <module>
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
remote: self.execute(*args, **cmd_options)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
remote: output = self.handle(*args, **options)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
remote: collected = self.collect()
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
remote: for path, storage in finder.list(self.ignore_patterns):
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
remote: for path in utils.get_files(storage, ignore_patterns):
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
remote: directories, files = storage.listdir(location)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 299, in listdir
remote: for entry in os.listdir(path):
remote: OSError: [Errno 2] No such file or directory: '/tmp/MakeCalls/Static'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
Staticfiles:
STATICFILES_DIRS = ([
os.path.join(os.path.dirname(BASE_DIR), 'MakeCalls', 'Static'),
])
STATIC_URL = '/Static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'MakeCalls', 'MakeCalls', 'Static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')
MEDIA_URL = os.path.join(BASE_DIR, 'media/')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
So I managed to fix this myself. The problem was that all my static files were organized in root/Static and served with STATICFILES_DIRS. However, for some reason, Heroku can't read this. So I put all static files in root/app/static and deleted the STATICFILES_DIRS in settings and it all worked!

I keep getting The below errors on my log file whenever i try to Push my django app to Heroku, Kindly assist on how i should go about in solving it,

Here is my log file
$ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/app/.heroku/python/lib/python2.7/site-packages/registration/admin.py", line 2, in <module>
from django.contrib.sites.models import RequestSite
ImportError: cannot import name RequestSite
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
RequestSite was moved from django.contrib.sites.models to django.contrib.sites.requests in Django 1.7, and the alias in models was removed in Django 1.9. You should ensure you are running a version of django-registration that is compatible with the version of Django you are using.

KeyError: 'AWS_STORAGE_BUCKET_NAME' When trying to deploy to Heroku

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: 4, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 408 bytes | 0 bytes/s, done.
Total 4 (delta 3), 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, v10
remote: https://article-django.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/article-django.git
070a1af..c4bbac5 master -> master
Then I did heroku run python ./manage.py collectstatic --noinput and got this traceback:
Running `python ./manage.py collectstatic --noinput` attached to terminal... up, run.8499
/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['AWS_STORAGE_BUCKET_NAME']
File "/app/.heroku/python/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'AWS_STORAGE_BUCKET_NAME'
I also have my Procfile:
web: gunicorn django_test.wsgi
And this snippet of my settings.py file:
try:
from local_settings import *
except Exception as e:
print e.message
if not DEBUG:
AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
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 committed all of the changes but I don't know why I still run into this error.
You need to set the AWS_STORAGE_BUCKET_NAME environment variable on Heroku.
Try the following (inserting the name of your S3 bucket):
heroku config:set AWS_STORAGE_BUCKET_NAME=<YOUR BUCKET NAME>

Collectstatic configuration error when deploying Django website on to Heroku and S3

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?
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']