[Solved]-Python/Django database username and password?

13๐Ÿ‘

โœ…

Yes! all of those information are necessary , there is no way you could connect to the database unless those values are
specified.

Yes! user and password are the actual credentials of your PostgreSQL database.

regarding deployment, you should set the correct IP/host where your production database is located. that might be example.com or xxx.xxx.xxx.xxx

I think you are concerned about security (revealing your database credentials in the source) if that is the case you could put your credentials in secure config file like .env and use this library to work with your config file.

๐Ÿ‘คmehari

2๐Ÿ‘

Specifically USER, PASSWORD, HOST, PORT? Is USER and PASSWORD values
that we can create in django settings.py? Or is this the actual
USER/PASSWORD of the database? Also, HOST is currently 127.0.0.1 for
localhost, but when deploying to production, do I change this to the
domain name (http://www.example.com)? And PORT, is it necessary?

The USER and PASSWORD is what you configure in the database, then you enter it in the file.

The HOST is the IP address or hostname where the server is running. In production, you have to check with your hosting provider for the correct details; it is rare that it is your domain name.

The PORT you only need to adjust if its different than the default port (5432). If it is different, your host will tell you.

Finally, keep in mind that http://www.example.com is not a domain name, this the the complete URL. The domain name is example.com, and the host is www, the fully qualified hostname is www.example.com.

๐Ÿ‘คBurhan Khalid

0๐Ÿ‘

Yes. See here for Django 2.1 or other versions. You could do the following:

  1. Login to Heroku
  2. Go to Resources
  3. Search for Postgres (Free version/Hobby)
  4. Then click on the newly generated database link
  5. Go to settings Under Admin, go to Credentials

Then you can add these variables in your Django production settings, preferably kept secret and called as environment variables () or you can define in the Heroku CLI (using the SET command in Windows). More explanation here.

๐Ÿ‘คPeter Doherty

Leave a comment