testdriven.io django raise 500 on heroku when tried to access postgres

115 Views Asked by At

I am following tutorial in https://testdriven.io/courses/tdd-django/deployment/ . Everything worked perfectly when I request get without accessing postgres, http://ancient-waters-04623.herokuapp.com/ping/ will return status 200

I done the migration and seed data

$ heroku run python manage.py migrate
$ heroku run python manage.py loaddata movies.json

when i run http://ancient-waters-04623.herokuapp.com/api/movies/ in my browser, it will give me error 500

the logs:

$ heroku logs --app=ancient-waters-04623 --tail

2020-09-07T10:13:51.045281+00:00 heroku[router]: at=info method=GET path="/ping/" host=ancient-waters-04623.herokuapp.com request_id=1895c42e-27d8-4d67-b5e8-98d0e5c3a3bd fwd="210.186.32.252" dyno=web.1 connect=0ms service=4ms status=200 bytes=225 protocol=http

I tried connect the database via dbeaver, and it connected and has correct data loaded.

I'm newbie in heroku either django, any help will be appreciated.

Thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

I was also getting a 500 back when accessing

https://APP_NAME.herokuapp.com/api/movies/

I turned on debug mode in Dockerfile.prod, and was able to view the DRF Browsable API with the expected data.

This led me to verify...

if not DEBUG:
    REST_FRAMEWORK = {
        "DEFAULT_RENDERER_CLASSES": (
            "rest_framework.renderers.JSONRenderer",
        )
    }

...in settings.py, where I determined I was missing the final ',' (see also: https://testdriven.io/courses/tdd-django/deployment/#H-1-browsable-api)

After fixing that and disabling debug mode again in Dockerfile.prod, I rebuilt the image, pushed it to the heroku container registry and released it. Now, I get the expected JSON response from

https://APP_NAME.herokuapp.com/api/movies/