Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

Heroku Bad Request (500)

Hi,

I'm going through the Deploying Django: Heroku workshop, and I'm doing excatly what Kenneth Love does, but I'm getting this Bad Request (500) when trying to visit my app - but the admin is working perfectly - any ideas how to fix this?

The entire project can be found at https://github.com/henrikac/KemiSpil

log

2018-01-14T14:56:38.742579+00:00 heroku[web.1]: Unidling
2018-01-14T14:56:38.742851+00:00 heroku[web.1]: State changed from down to starting
2018-01-14T14:56:42.934638+00:00 heroku[web.1]: Starting process with command `gunicorn --pythonpath kemispil kemispil.deploy --log-file -`
2018-01-14T14:56:44.981342+00:00 app[web.1]: [2018-01-14 14:56:44 +0000] [4] [INFO] Starting gunicorn 19.7.1
2018-01-14T14:56:44.982010+00:00 app[web.1]: [2018-01-14 14:56:44 +0000] [4] [INFO] Listening at: http://0.0.0.0:24819 (4)
2018-01-14T14:56:44.982191+00:00 app[web.1]: [2018-01-14 14:56:44 +0000] [4] [INFO] Using worker: sync
2018-01-14T14:56:44.985564+00:00 app[web.1]: [2018-01-14 14:56:44 +0000] [8] [INFO] Booting worker with pid: 8
2018-01-14T14:56:45.044206+00:00 app[web.1]: [2018-01-14 14:56:45 +0000] [9] [INFO] Booting worker with pid: 9
2018-01-14T14:56:45.594801+00:00 heroku[web.1]: State changed from starting to up
2018-01-14T14:56:46.017031+00:00 heroku[router]: at=info method=GET path="/" host=kemispil.herokuapp.com request_id=e1c7ca3a-344b-4ced-baac-05fd0375d4c2 fwd="185.126.109.95" dyno=web.
1 connect=0ms service=99ms status=500 bytes=234 protocol=https
2018-01-14T14:56:46.016839+00:00 app[web.1]: 10.120.19.142 - - [14/Jan/2018:15:56:46 +0100] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (K
HTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"

deploy_settings/init.py

import dj_database_url

from kemispil.settings import *

DEBUG = False
TEMPLATE_DEBUG = DEBUG

ALLOWED_HOSTS = [
    'localhost',
    '.herokuapp.com'
]

SECRET_KEY = get_env_variable("SECRET_KEY")

db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

deploy.py

"""
WSGI config for kemispil project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os

from whitenoise.django import DjangoWhiteNoise

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kemispil.deploy_settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

Procfile

web: gunicorn --pythonpath kemispil kemispil.deploy --log-file -

requirements.txt

Django==2.0
gunicorn==19.7.1
dj-database-url==0.4.2
psycopg2==2.7.3.2
whitenoise==3.3.1

runtime.txt

python-3.6.4

edit*

Oops, missed the repo. Going to import it and tinker, but just noticed your middleware classes were missing some I had.

https://devcenter.heroku.com/articles/django-assets

I had similar issues last night (static files) and following that resolved my issue. Let us know if you solve it before hand?

Nice coding btw - super easy to read

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

but just noticed your middleware classes were missing some I had - what middleware classes? :-)

I read that link earlier but I don't think it's because of staticfiles, because the admin-area looks perfect.

I will let you know if I solve it :-)

1 Answer

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

Solved the problem! :-D

It turned out to be my template settings that was causing the problem:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],  # Before: 'DIRS': ['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',
            ],
        },
    },
]

But thank you Blaine McCarthy for taking the time to help me :-)