django-simple-deploy icon indicating copy to clipboard operation
django-simple-deploy copied to clipboard

glasnt tries django-simple-deploy on heroku

Open glasnt opened this issue 3 years ago • 3 comments

I tried out the heroku deployment on a very smol sample project https://github.com/glasnt/django-simple-project

I got the deployment happening, but with some limitations:

The app deployed, but the admin looked funny (no static)

Screen Shot 2022-10-22 at 12 11 55 pm

I looked up the code and you're using whitenoise, but not configuring it. It's been mentioned before.

I added this manually to my settings:

import os
if 'ON_HEROKU' in os.environ:
   ...
+    # from https://whitenoise.evans.io/en/stable/#quickstart-for-django-apps, install whitenoise after SecurityMiddleware
+    i = MIDDLEWARE.index("django.middleware.security.SecurityMiddleware")
+    MIDDLEWARE.insert(i + 1,"whitenoise.middleware.WhiteNoiseMiddleware")

Heroku will automatically run collectstatic as part of the push:

$ git commit -av
[main 1521f91] update heroku/whitenoise
 1 file changed, 8 insertions(+), 1 deletion(-)
$ git push heroku main
remote: -----> $ python manage.py collectstatic --noinput
remote:        131 static files copied to '/tmp/build_47e52420/staticfiles'.

So once I ran this, the admin looked okay again:

Screen Shot 2022-10-22 at 12 45 45 pm

The other issue I had is that because blank database, I had no django admin login.

I know I can fix this in heroku by running heroku run python manage.py createsuperuser and interactively re-create the admin user, which I did.


My simple app contained a Procfile already, so this file was not overridden (but it also already ran locally).


Still to do:

  • [x] write introduction in discussion https://github.com/ehmatthes/django-simple-deploy/discussions/130#discussioncomment-3942286
  • [x] try platform.sh #158, #159
  • [x] try fly.io #156
    • [x] Noting differences
  • [ ] new platform shenanigans

glasnt avatar Oct 22 '22 19:10 glasnt