Saving to Database from Heroku

Hi, All

I managed to fix my previous deployment issue – a number of faux pas’ :-).

However, even though I can save media files and both my media & static files are being served from AWS S3 buckets, I can no longer save to the media files.
I have run a migrate and set up a new superuser ala: “heroku run python manage.py migrate”

Any thoughts?

Sam

from pathlib import Path
from environs import Env
# from django.conf.global_settings import STATICFILES_DIRS, STATICFILES_STORAGE, DEFAULT_FILE_STORAGE
import os
from dotenv import load_dotenv
load_dotenv()

env = Env()
env.read_env()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DEBUG", default=False)

ALLOWED_HOSTS = [".herokuapp.com", "localhost", "127.0.0.1"]

# Application definition

SITE_ID = 1

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'contact',
    'main',
    'embed_video',
    'storages',
    'django.contrib.sites',
    'django.contrib.sitemaps',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'config.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [str(BASE_DIR.joinpath('templates'))],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'config.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    "default": env.dj_db_url("DATABASE_URL")
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

# STATIC_URL = '/static/'
# STATICFILES_DIRS = [str(BASE_DIR.joinpath('static'))]

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = 'bax-static'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
AWS_DEFAULT_ACL = 'public-read'

AWS_LOCATION = 'static'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    ]


STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
DEFAULT_FILE_STORAGE = 'config.storages.MediaStore'


# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


CONTACT_EMAIL = 'bell.samuel@mac.com'
ADMIN_EMAIL = ['bell.samuel@icloud.com',]


# Twilio SendGrid
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = os.environ.get('SENDGRID_API_KEY')

FROM_EMAIL = 'bell.samuel@icloud.com' # replace with your address
SENDGRID_API_KEY = os.environ.get('SENDGRID_API_KEY')

DEFAULT_FILE_STORAGE = 'config.storages.MediaStore'
# MEDIA_URL = '/media/'
# MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Hi bellsamuel, I think there’s a mistake in the quoted sentence. Also if you’re getting an error from somewhere, please include the error and the stack trace. If you can also let us know what you’re trying, what happens and what you expected to happen, we’ll be able to better assist.

Hi, Tim

Thanks for the reply.

I’m very new to Python and Django – trying to teach myself.
Basically, I followed a tutorial to build a website with a blog and contact form.

During that process, it seemed best to use AWS for static file hosting, which is CSS, minimal javascript, some SVG’s and images.

I also have a media folder which was for uploading images for the blog, which works locally. Since deploying to Heroku, I can’t upload to that folder – and – my SendGrid contact form has stopped working, so I suspect it’s something to do with the API keys and the .env file.

The text fields, slug field parts of the blog seem to be functioning correctly, so I assume the database is wired up as it should be.

What would be the best code snippets to upload?

Thanks so much for any help, this forum is excellent.

Sam

P.S

Below I have pasted the Heroku log, .env file and Settings.py.
I’ll change the secret key before deploying again.

2021-11-08T21:35:34.923705+00:00 heroku[router]: at=info method=GET path="/admin/blog/post/" host=bax-conversions.herokuapp.com request_id=e4ee2256-5d18-44d1-b593-23b40ab32509 fwd="90.213.81.88" dyno=web.1 connect=0ms service=182ms status=200 bytes=8352 protocol=https
2021-11-08T21:35:34.924336+00:00 app[web.1]: 10.1.95.149 - - [08/Nov/2021:21:35:34 +0000] "GET /admin/blog/post/ HTTP/1.1" 200 7721 "https://bax-conversions.herokuapp.com/admin/blog/post/1/change/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:35:35.185805+00:00 heroku[router]: at=info method=GET path="/admin/jsi18n/" host=bax-conversions.herokuapp.com request_id=6bae4d1e-c82e-42d6-b22f-4da332a17161 fwd="90.213.81.88" dyno=web.1 connect=0ms service=114ms status=200 bytes=3458 protocol=https
2021-11-08T21:35:35.186588+00:00 app[web.1]: 10.1.95.149 - - [08/Nov/2021:21:35:35 +0000] "GET /admin/jsi18n/ HTTP/1.1" 200 3195 "https://bax-conversions.herokuapp.com/admin/blog/post/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:36:03.669470+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=be0360eb-1977-44d3-be07-a32e34a9998a fwd="90.213.81.88" dyno=web.1 connect=0ms service=3ms status=200 bytes=11966 protocol=https
2021-11-08T21:36:03.670097+00:00 app[web.1]: 10.1.95.149 - - [08/Nov/2021:21:36:03 +0000] "GET / HTTP/1.1" 200 11724 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:36:06.813480+00:00 heroku[router]: at=info method=GET path="/blog/" host=bax-conversions.herokuapp.com request_id=9db6079f-20ab-4666-be8d-1db902c1d5e4 fwd="90.213.81.88" dyno=web.1 connect=0ms service=60ms status=200 bytes=8063 protocol=https
2021-11-08T21:36:06.814158+00:00 app[web.1]: 10.1.95.149 - - [08/Nov/2021:21:36:06 +0000] "GET /blog/ HTTP/1.1" 200 7822 "https://bax-conversions.herokuapp.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:37:53.369734+00:00 app[web.1]: 10.1.88.120 - - [08/Nov/2021:21:37:53 +0000] "GET /blog/ HTTP/1.1" 200 7822 "https://bax-conversions.herokuapp.com/blog/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:37:53.369997+00:00 heroku[router]: at=info method=GET path="/blog/" host=bax-conversions.herokuapp.com request_id=0cb5460b-fe1f-4a7c-ad81-e082cf6d27a1 fwd="90.213.81.88" dyno=web.1 connect=0ms service=124ms status=200 bytes=8063 protocol=https
2021-11-08T21:37:59.260788+00:00 app[web.1]: 10.1.88.120 - - [08/Nov/2021:21:37:59 +0000] "GET /admin/blog/post/1/change/ HTTP/1.1" 200 10532 "https://bax-conversions.herokuapp.com/admin/blog/post/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:37:59.261344+00:00 heroku[router]: at=info method=GET path="/admin/blog/post/1/change/" host=bax-conversions.herokuapp.com request_id=b887713c-a44d-4a31-af77-2749b901e7e1 fwd="90.213.81.88" dyno=web.1 connect=0ms service=82ms status=200 bytes=11067 protocol=https
2021-11-08T21:37:59.557604+00:00 app[web.1]: 10.1.88.120 - - [08/Nov/2021:21:37:59 +0000] "GET /admin/jsi18n/ HTTP/1.1" 200 3195 "https://bax-conversions.herokuapp.com/admin/blog/post/1/change/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:37:59.557730+00:00 heroku[router]: at=info method=GET path="/admin/jsi18n/" host=bax-conversions.herokuapp.com request_id=8cabf65c-0ee5-4881-b9d8-c5da0e4e759a fwd="90.213.81.88" dyno=web.1 connect=0ms service=148ms status=200 bytes=3458 protocol=https
2021-11-08T21:38:14.244116+00:00 app[web.1]: 10.1.88.120 - - [08/Nov/2021:21:38:14 +0000] "POST /admin/blog/post/1/change/ HTTP/1.1" 500 145 "https://bax-conversions.herokuapp.com/admin/blog/post/1/change/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:38:14.244525+00:00 heroku[router]: at=info method=POST path="/admin/blog/post/1/change/" host=bax-conversions.herokuapp.com request_id=76aa8e23-a56f-454b-8803-a1e1eb29d0db fwd="90.213.81.88" dyno=web.1 connect=0ms service=5512ms status=500 bytes=403 protocol=https
2021-11-08T21:38:17.863657+00:00 app[web.1]: 10.1.88.120 - - [08/Nov/2021:21:38:17 +0000] "GET /admin/blog/post/1/change/ HTTP/1.1" 200 10532 "https://bax-conversions.herokuapp.com/admin/blog/post/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:38:17.864009+00:00 heroku[router]: at=info method=GET path="/admin/blog/post/1/change/" host=bax-conversions.herokuapp.com request_id=e11df3cc-29e2-4b1b-9dc5-ff8abc6dc934 fwd="90.213.81.88" dyno=web.1 connect=0ms service=109ms status=200 bytes=11067 protocol=https
2021-11-08T21:57:24.602373+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=489fc47f-0ba0-4c48-b0dd-0d101a1d00ab fwd="90.213.81.88" dyno=web.1 connect=0ms service=3ms status=200 bytes=11966 protocol=https
2021-11-08T21:57:24.602756+00:00 app[web.1]: 10.1.44.28 - - [08/Nov/2021:21:57:24 +0000] "GET / HTTP/1.1" 200 11724 "https://dashboard.heroku.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:57:29.002314+00:00 heroku[router]: at=info method=GET path="/contact/" host=bax-conversions.herokuapp.com request_id=3da559b5-7c19-4345-80fc-867284c7fc3b fwd="90.213.81.88" dyno=web.1 connect=0ms service=8ms status=200 bytes=9111 protocol=https
2021-11-08T21:57:29.002824+00:00 app[web.1]: 10.1.44.28 - - [08/Nov/2021:21:57:29 +0000] "GET /contact/ HTTP/1.1" 200 8689 "https://bax-conversions.herokuapp.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:57:39.874560+00:00 heroku[router]: at=info method=POST path="/contact/" host=bax-conversions.herokuapp.com request_id=45cb7762-9495-4539-ae2b-68f77cd65ac3 fwd="90.213.81.88" dyno=web.1 connect=0ms service=125ms status=500 bytes=403 protocol=https
2021-11-08T21:57:39.875072+00:00 app[web.1]: 10.1.44.28 - - [08/Nov/2021:21:57:39 +0000] "POST /contact/ HTTP/1.1" 500 145 "https://bax-conversions.herokuapp.com/contact/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:57:57.975841+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=8b3c6efe-4617-4f00-85d8-a13538c59349 fwd="90.213.81.88" dyno=web.1 connect=0ms service=3ms status=200 bytes=11966 protocol=https
2021-11-08T21:57:57.976316+00:00 app[web.1]: 10.1.44.28 - - [08/Nov/2021:21:57:57 +0000] "GET / HTTP/1.1" 200 11724 "https://dashboard.heroku.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T21:58:00.804350+00:00 heroku[router]: at=info method=GET path="/sign_up/" host=bax-conversions.herokuapp.com request_id=8af35f25-858c-4332-b4ba-5bcd00a5ac76 fwd="90.213.81.88" dyno=web.1 connect=0ms service=2ms status=200 bytes=423 protocol=https
2021-11-08T21:58:00.804748+00:00 app[web.1]: 10.1.44.28 - - [08/Nov/2021:21:58:00 +0000] "GET /sign_up/ HTTP/1.1" 200 183 "https://bax-conversions.herokuapp.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T22:01:52.238816+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=12ae89db-f064-49d0-bfd8-4ae7d65d157d fwd="90.213.81.88" dyno=web.1 connect=0ms service=4ms status=200 bytes=11966 protocol=https
2021-11-08T22:01:52.239148+00:00 app[web.1]: 10.1.4.231 - - [08/Nov/2021:22:01:52 +0000] "GET / HTTP/1.1" 200 11724 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T22:04:04.282460+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=8d6087bd-6d99-46d6-9523-ed6fc1a1e6de fwd="90.213.81.88" dyno=web.1 connect=0ms service=3ms status=200 bytes=11966 protocol=https
2021-11-08T22:04:04.282966+00:00 app[web.1]: 10.1.33.220 - - [08/Nov/2021:22:04:04 +0000] "GET / HTTP/1.1" 200 11724 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-08T22:04:41.373770+00:00 app[web.1]: 10.1.22.222 - - [08/Nov/2021:22:04:41 +0000] "GET /favicon.ico HTTP/1.1" 404 179 "https://bax-conversions.herokuapp.com/history/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-08T22:04:41.374134+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=bax-conversions.herokuapp.com request_id=7ccf27c3-0577-4f08-bbf9-0ebd3759f7c7 fwd="90.213.81.88" dyno=web.1 connect=0ms service=2ms status=404 bytes=411 protocol=https
2021-11-08T22:04:46.288877+00:00 app[web.1]: 10.1.22.222 - - [08/Nov/2021:22:04:46 +0000] "GET /science/ HTTP/1.1" 200 15319 "https://bax-conversions.herokuapp.com/history/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-08T22:04:46.289501+00:00 heroku[router]: at=info method=GET path="/science/" host=bax-conversions.herokuapp.com request_id=f1399f0c-971a-4e96-9523-d5088b1fd2eb fwd="90.213.81.88" dyno=web.1 connect=0ms service=6ms status=200 bytes=15561 protocol=https
2021-11-08T22:36:28.089831+00:00 heroku[web.1]: Idling
2021-11-08T22:36:28.111506+00:00 heroku[web.1]: State changed from up to down
2021-11-08T22:36:28.875407+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-11-08T22:36:28.945563+00:00 app[web.1]: [2021-11-08 22:36:28 +0000] [10] [INFO] Worker exiting (pid: 10)
2021-11-08T22:36:28.945956+00:00 app[web.1]: [2021-11-08 22:36:28 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-11-08T22:36:28.950937+00:00 app[web.1]: [2021-11-08 22:36:28 +0000] [4] [INFO] Handling signal: term
2021-11-08T22:36:28.956238+00:00 app[web.1]: [2021-11-08 22:36:28 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2021-11-08T22:36:28.957055+00:00 app[web.1]: [2021-11-08 22:36:28 +0000] [4] [WARNING] Worker with pid 10 was terminated due to signal 15
2021-11-08T22:36:29.051499+00:00 app[web.1]: [2021-11-08 22:36:29 +0000] [4] [INFO] Shutting down: Master
2021-11-08T22:36:29.216288+00:00 heroku[web.1]: Process exited with status 0
2021-11-09T10:51:00.712051+00:00 heroku[web.1]: Unidling
2021-11-09T10:51:00.729607+00:00 heroku[web.1]: State changed from down to starting
2021-11-09T10:51:08.065539+00:00 heroku[web.1]: Starting process with command `gunicorn config.wsgi --log-file -`
2021-11-09T10:51:09.087671+00:00 app[web.1]: [2021-11-09 10:51:09 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-11-09T10:51:09.087957+00:00 app[web.1]: [2021-11-09 10:51:09 +0000] [4] [INFO] Listening at: http://0.0.0.0:30018 (4)
2021-11-09T10:51:09.087997+00:00 app[web.1]: [2021-11-09 10:51:09 +0000] [4] [INFO] Using worker: sync
2021-11-09T10:51:09.091157+00:00 app[web.1]: [2021-11-09 10:51:09 +0000] [9] [INFO] Booting worker with pid: 9
2021-11-09T10:51:09.134580+00:00 app[web.1]: [2021-11-09 10:51:09 +0000] [10] [INFO] Booting worker with pid: 10
2021-11-09T10:51:09.298680+00:00 heroku[web.1]: State changed from starting to up
2021-11-09T10:51:11.538709+00:00 app[web.1]: 10.1.2.126 - - [09/Nov/2021:10:51:11 +0000] "GET /science/ HTTP/1.1" 200 15319 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:11.540372+00:00 heroku[router]: at=info method=GET path="/science/" host=bax-conversions.herokuapp.com request_id=9e248bac-376a-4c6c-8448-8a2c140acaf3 fwd="194.66.216.41" dyno=web.1 connect=0ms service=1462ms status=200 bytes=15561 protocol=https
2021-11-09T10:51:11.541760+00:00 app[web.1]: 10.1.47.251 - - [09/Nov/2021:10:51:11 +0000] "GET / HTTP/1.1" 200 11724 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:11.542869+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=45a4562c-e4f5-484a-b744-ff00dd63b027 fwd="194.66.216.41" dyno=web.1 connect=0ms service=1233ms status=200 bytes=11966 protocol=https
2021-11-09T10:51:11.543470+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:51:11 +0000] "GET /contact/ HTTP/1.1" 200 8689 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:11.544133+00:00 heroku[router]: at=info method=GET path="/contact/" host=bax-conversions.herokuapp.com request_id=e82774ec-3063-4d01-8122-70a06f90af1e fwd="194.66.216.41" dyno=web.1 connect=0ms service=1261ms status=200 bytes=9111 protocol=https
2021-11-09T10:51:11.544620+00:00 app[web.1]: 10.1.4.64 - - [09/Nov/2021:10:51:11 +0000] "GET /history/ HTTP/1.1" 200 18578 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:11.546214+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=b57807ad-538d-476b-9356-134c7c97112d fwd="194.66.216.41" dyno=web.1 connect=0ms service=766ms status=200 bytes=11966 protocol=https
2021-11-09T10:51:11.546563+00:00 app[web.1]: 10.1.95.149 - - [09/Nov/2021:10:51:11 +0000] "GET / HTTP/1.1" 200 11724 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:11.546567+00:00 heroku[router]: at=info method=GET path="/history/" host=bax-conversions.herokuapp.com request_id=084e7c8c-ed3d-4c66-abed-90c652058b0f fwd="194.66.216.41" dyno=web.1 connect=0ms service=928ms status=200 bytes=18820 protocol=https
2021-11-09T10:51:11.546899+00:00 heroku[router]: at=info method=GET path="/likes/" host=bax-conversions.herokuapp.com request_id=ab421aa6-5a93-4c8f-be1c-9011c57b4a2c fwd="194.66.216.41" dyno=web.1 connect=0ms service=531ms status=200 bytes=18666 protocol=https
2021-11-09T10:51:11.546971+00:00 app[web.1]: 10.1.4.152 - - [09/Nov/2021:10:51:11 +0000] "GET /likes/ HTTP/1.1" 200 18424 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:12.544106+00:00 heroku[router]: at=info method=GET path="/contact/" host=bax-conversions.herokuapp.com request_id=add700aa-4828-47f7-8024-5c2ad018b453 fwd="194.66.216.41" dyno=web.1 connect=0ms service=8ms status=200 bytes=9111 protocol=https
2021-11-09T10:51:12.545451+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:51:12 +0000] "GET /contact/ HTTP/1.1" 200 8689 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:15.685824+00:00 heroku[router]: at=info method=GET path="/science/" host=bax-conversions.herokuapp.com request_id=7adf3515-359b-4c09-8dd9-ecb33ba2fa54 fwd="194.66.216.41" dyno=web.1 connect=0ms service=4ms status=200 bytes=15561 protocol=https
2021-11-09T10:51:15.686978+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:51:15 +0000] "GET /science/ HTTP/1.1" 200 15319 "https://bax-conversions.herokuapp.com/contact/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:51:18.775511+00:00 heroku[router]: at=info method=GET path="/" host=bax-conversions.herokuapp.com request_id=65799a19-13c8-4294-a162-ca706c26334e fwd="194.66.216.41" dyno=web.1 connect=0ms service=4ms status=200 bytes=11966 protocol=https
2021-11-09T10:51:18.776969+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:51:18 +0000] "GET / HTTP/1.1" 200 11724 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:52:14.872203+00:00 heroku[router]: at=info method=GET path="/science/" host=bax-conversions.herokuapp.com request_id=773d0cc7-a920-4dc3-a933-5f9103d707d1 fwd="194.66.216.41" dyno=web.1 connect=0ms service=3ms status=200 bytes=15561 protocol=https
2021-11-09T10:52:14.873224+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:52:14 +0000] "GET /science/ HTTP/1.1" 200 15319 "https://bax-conversions.herokuapp.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:52:18.108324+00:00 heroku[router]: at=info method=GET path="/process/" host=bax-conversions.herokuapp.com request_id=e6d06a80-cd14-4eca-ab6a-60550bf72e91 fwd="194.66.216.41" dyno=web.1 connect=0ms service=4ms status=200 bytes=18045 protocol=https
2021-11-09T10:52:18.109215+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:52:18 +0000] "GET /process/ HTTP/1.1" 200 17803 "https://bax-conversions.herokuapp.com/science/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:52:20.162410+00:00 heroku[router]: at=info method=GET path="/team/" host=bax-conversions.herokuapp.com request_id=09d6ddd8-3943-4c6f-8e43-322c5df7b33e fwd="194.66.216.41" dyno=web.1 connect=0ms service=3ms status=200 bytes=22218 protocol=https
2021-11-09T10:52:20.163504+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:52:20 +0000] "GET /team/ HTTP/1.1" 200 21976 "https://bax-conversions.herokuapp.com/process/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:52:28.227916+00:00 heroku[router]: at=info method=GET path="/testimonials/" host=bax-conversions.herokuapp.com request_id=3bd86c4e-6dca-416a-a80c-3a2af9552d13 fwd="194.66.216.41" dyno=web.1 connect=0ms service=4ms status=200 bytes=19098 protocol=https
2021-11-09T10:52:28.228829+00:00 app[web.1]: 10.1.36.172 - - [09/Nov/2021:10:52:28 +0000] "GET /testimonials/ HTTP/1.1" 200 18856 "https://bax-conversions.herokuapp.com/team/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:54:46.058938+00:00 app[web.1]: Backend wasn't recognised (`None`)
2021-11-09T10:54:46.058946+00:00 app[web.1]: Traceback (most recent call last):
2021-11-09T10:54:46.058947+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/embed_video/templatetags/embed_video_tags.py", line 117, in render
2021-11-09T10:54:46.058948+00:00 app[web.1]: return self.embed(url, size, context=context, **options)
2021-11-09T10:54:46.058948+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/embed_video/templatetags/embed_video_tags.py", line 196, in embed
2021-11-09T10:54:46.058949+00:00 app[web.1]: backend = cls.get_backend(url, context=context, **options)
2021-11-09T10:54:46.058949+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/embed_video/templatetags/embed_video_tags.py", line 174, in get_backend
2021-11-09T10:54:46.058949+00:00 app[web.1]: else detect_backend(str(backend_or_url))
2021-11-09T10:54:46.058950+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/embed_video/backends.py", line 64, in detect_backend
2021-11-09T10:54:46.058950+00:00 app[web.1]: raise UnknownBackendException
2021-11-09T10:54:46.058951+00:00 app[web.1]: embed_video.backends.UnknownBackendException
2021-11-09T10:54:46.060331+00:00 app[web.1]: 10.1.44.28 - - [09/Nov/2021:10:54:46 +0000] "GET /blog/one HTTP/1.1" 200 7380 "https://bax-conversions.herokuapp.com/blog/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
2021-11-09T10:54:46.061070+00:00 heroku[router]: at=info method=GET path="/blog/one" host=bax-conversions.herokuapp.com request_id=51f55665-fc32-4fe3-9840-d003f9e23837 fwd="194.66.216.41" dyno=web.1 connect=0ms service=109ms status=200 bytes=7621 protocol=https
2021-11-09T10:57:36.340114+00:00 app[web.1]: 10.1.88.120 - - [09/Nov/2021:10:57:36 +0000] "GET /contact/ HTTP/1.1" 200 8689 "https://bax-conversions.herokuapp.com/testimonials/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:57:36.341524+00:00 heroku[router]: at=info method=GET path="/contact/" host=bax-conversions.herokuapp.com request_id=4d0acdb7-e5b2-4ed2-a9ed-057316503113 fwd="194.66.216.41" dyno=web.1 connect=0ms service=5ms status=200 bytes=9111 protocol=https
2021-11-09T10:57:43.579828+00:00 app[web.1]: 10.1.88.120 - - [09/Nov/2021:10:57:43 +0000] "POST /contact/ HTTP/1.1" 500 145 "https://bax-conversions.herokuapp.com/contact/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:57:43.581292+00:00 heroku[router]: at=info method=POST path="/contact/" host=bax-conversions.herokuapp.com request_id=95990fd0-bd6f-4332-b8ee-46fcb3470939 fwd="194.66.216.41" dyno=web.1 connect=0ms service=858ms status=500 bytes=403 protocol=https
2021-11-09T10:57:43.761341+00:00 app[web.1]: 10.1.15.77 - - [09/Nov/2021:10:57:43 +0000] "POST /contact/ HTTP/1.1" 500 145 "https://bax-conversions.herokuapp.com/contact/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4695.0 Safari/537.36"
2021-11-09T10:57:43.761388+00:00 heroku[router]: at=info method=POST path="/contact/" host=bax-conversions.herokuapp.com request_id=7c803932-4b49-4758-90f1-95bd843d6ee5 fwd="194.66.216.41" dyno=web.1 connect=0ms service=56ms status=500 bytes=403 protocol=https

from pathlib import Path
from environs import Env
from django.conf.global_settings import STATICFILES_DIRS, STATICFILES_STORAGE, DEFAULT_FILE_STORAGE
import os
from dotenv import load_dotenv
load_dotenv()

env = Env()
env.read_env()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DEBUG", default=False)

ALLOWED_HOSTS = [".herokuapp.com", "localhost", "127.0.0.1"]

# Application definition

SITE_ID = 1

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'contact',
    'main',
    'embed_video',
    'storages',
    'django.contrib.sites',
    'django.contrib.sitemaps',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'config.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [str(BASE_DIR.joinpath('templates'))],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'config.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    "default": env.dj_db_url("DATABASE_URL")
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'
# STATICFILES_DIRS = [str(BASE_DIR.joinpath('static'))]

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = 'bax-static'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
AWS_DEFAULT_ACL = 'public-read'

AWS_LOCATION = 'static'
# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]


STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
DEFAULT_FILE_STORAGE = 'config.storages.MediaStore'


# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


CONTACT_EMAIL = 'bell.samuel@mac.com'
ADMIN_EMAIL = ['bell.samuel@icloud.com',]


# Twilio SendGrid
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = os.environ.get('SENDGRID_API_KEY')

FROM_EMAIL = 'bell.samuel@icloud.com' # replace with your address
SENDGRID_API_KEY = os.environ.get('SENDGRID_API_KEY')

DEFAULT_FILE_STORAGE = 'config.storages.MediaStore'
# MEDIA_URL = '/media/'
# MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Unfortunately, you can’t store media files on heroku’s app servers. You’ll need to store them in some other place such as S3, the database, etc.

my SendGrid contact form has stopped working, so I suspect it’s something to do with the API keys and the .env file.

I’m assuming the .env file contains the secrets, keys, etc that is not committed into the git repo. Heroku expects you to use the configuration/environment variables rather than creating files per app server. Check out heroku config --help or the heroku docs for more detailed information.

1 Like

I don’t recommend storing images in the database. I threw it out there as an example of a persistent storage location.

Got it.

All the images are stored on S3 buckets.

In some exploration earlier today reading the Mozilla page on deployment, you’re right, I’m sure once I configure it correctly it will do what it isn’t.

Thanks, Tim :+1:

Best of luck! Let us know if you hit any obstacles.