0

I'm trying to deploy a simple django application (SQLite3) to render but I can't log in to the admin page even with valid superuser credentials. I could authenticate locally, but not while on the render deployed version.

Your help is much appreciated!

  • Did you create super user on deployed version? If yes, then what error do you see? – marke Jun 02 '22 at 08:27
  • No, I didn't. Should I create a super user on production?. This is the error I got: `Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive.` –  Jun 02 '22 at 15:45
  • sure, you have to run python manage.py createsuperuser, if you don't do that there will be no superuser – marke Jun 02 '22 at 17:16
  • Thank you, I understand. Is there any free approach to run `python manage.py createsuperuser` without using the render shell? –  Jun 02 '22 at 17:49
  • yeah, you can do it as part of deployment script I guess, depends on how you deploy, here https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-createsuperuser you can see how to do it without user input – marke Jun 03 '22 at 05:16
  • Thank you so much. I read the documentation, and I could figure out how to create a superuser from the deployment script. However, I run through another issue. Auto deployment on Render clears my data after every change I push to the repository, and I need to start all over again creating a new data from the admin page. It seems like the database instance I created on Render doesn't save my data. –  Jun 03 '22 at 20:04
  • I don't know Render and it sounds like Render-specific issue so to speak. What database are you using? – marke Jun 04 '22 at 09:53
  • Thank you, I fixed it. I'm using SQLite locally for testing and PostgreSQL on production. The reason why the database gets wiped after every update is I kept the SQLite configuration in `settings.py` and I didn't configure properly on the same file the database instance I added on production. –  Jun 04 '22 at 10:38

2 Answers2

2

Try running python manage.py createsuperuser in the Render Shell.

Documentation on creating a Django admin account on Render deployments.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Audrey
  • 86
  • 5
1

As a substitute to running python manage.py createsuperuser on Render Shell, you can do a quick deployment with python manage.py createsuperuser --no-input on your build script and have environment variables such as DJANGO_SUPERUSER_USERNAME set. You then have to remove this hack for later builds.

See https://stackoverflow.com/a/59467533/4932353 for more information.

setnoset
  • 249
  • 3
  • 7