1

EDIT - New, similar question -: django.db.backends.postgresql_psycopg2, for 'NAME', I put the database name, for 'USER' and 'PASSWORD' I put the username and password I created.. and then what do I put for host and port? host I put 127.0.0.1? And port I put 5432? This was the host and port I received when installing PostgreSQL. Also, when I installed PostgreSQL, it asked me to create a password for the database, when do I use that password?

Original question which has now been answered: I'm new to databases and django, I was reading the djangobook (http://www.djangobook.com/en/2.0/chapter05.html) and I installed PostgreSQL.

In the djangobook, it says "We’ll assume you’ve set up a database server, activated it, and created a database within it (e.g., using a CREATE DATABASE statement)"

What I did was installed PostgreSQL and psycopg2-2.5.1 and then created a user and database using these instructions: https://confluence.atlassian.com/display/CONF30/Database+Setup+for+PostgreSQL+on+Windows

However, I stopped when I reached the "Setting up Confluence to use the PostgreSQL Database". Do I need to do the "Setting up Confluence to use the PostgreSQL Database" in order to use by database while building an app using django?

1 Answer 1

3

No, you'll only need the first section, and only a part of it at that.

PostgreSQL is a database engine that can service many applications. Confluence is one of these applications. You were following a guide to install Confluence, which happened to also include a section on installing PostgreSQL. If you only followed the PostgreSQL installation part, you should be fine.

If you followed the whole first section, though, then one thing you might want to change is the user. confuser indicates that the user is being used for Confluence, which isn't really the case if you're not using it for Confluence. django might be a more appropriate user name.

Once you've got PostgreSQL and psycopg installed and a django user set up, it's a fairly simple matter to tell Django how to connect. As you discovered, you'll want to set

  • the backend to django.db.backends.postgresql_psycopg2,
  • the name to the name of the database you created
  • the host to the IP address of the computer running PostgreSQL; in your case, you'll probably be running Django on the same computer that PostgreSQL is running on, so you can use the special IP address 127.0.0.1, which always means “this computer”, and
  • the port to whatever number you gave the PostgreSQL installer (probably 5432).

You also asked about the difference between the password you gave the PostgreSQL installer and the user you created for Django. In short, you want to create users for each of your applications, so if for some reason the credentials are compromised and someone can connect with them, they're restricted to that application's database. The postgres user with the password you gave the installer should not be given to applications, but is for administration: creating new users and databases, for example.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh okay, so to use a database with a django, I first create a new user, password and database. Make the user the owner of the database, and then for 'ENGINE', I put django.db.backends.postgresql_psycopg2, for 'NAME', I put the database name, for 'USER' and 'PASSWORD' I put the username and password I created.. and then what do I put for host and port? host I put 127.0.0.1? And port I put 5432? This was the host and port I received when installing PostgreSQL. Also, when I installed PostgreSQL, it asked me to create a password for the database, when do I use that password?
@user216485: For host, you put the IP address of the computer running the database. 127.0.0.1 always means “this computer”, so if you're running the Django application on the same computer as the database, then yes, you'd use 127.0.0.1. The port should be the same number you gave PostgreSQL when installing it, which is probably 5432. You'll give Django the username and password for the user you created; the username postgres and the password you gave the PostgreSQL installer are used when you want to create new users or new databases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.