I'm playing with Django, a really snazzy template based, database backed web app engine, again this week. I originally encountered the tool when I started making Google App Engine applications years ago. One of the last extant apps from that era is my ham radio exam practice app.
This week, while ramping up another project, I did something new, I connected Django to a PostgreSQL database. I'd always used MySQL in the past. There were steps. They weren't particularly difficult, but I couldn't find much in the way of documentation, and when I did, following the steps in order didn't work for me. Here's what did:
- Install psycopg2. (You may need to install psycopg instead depending on your version of Django. Django does a good job of telling you what it actually needs later in the process.
- Of course, make sure PostgresSQL is already up and running. You'll need to be able to access the postgres user who's default password is in fact postgres.
- Setup up the database with a user that Django will access. To setup the Django database and Django user, (aside, I found these instructions here, and they're great, and more detailed than this post, but like I say, but the ordering of later steps didn't work for me, and I wanted to capture what to do, becuase, you know, fluid internet), you'll:
- CREATE DATABASE usersDB;
- CREATE USER sammy WITH PASSWORD 'pa$$word';
- GRANT ALL PRIVILEGES ON DATABASE usersDB TO sammy;
- ALTER ROLE sammy SET client_encoding TO 'utf8'; ALTER ROLE sammy SET default_transaction_isolation TO 'read committed'; ALTER ROLE sammy SET timezone TO 'UTC';
- And then exit the database.
- Once the database is setup, you'll create a Django App, which, again, is well documented here.
- And then! Don't test the app yet becuase it's not connected to the database. This is the step that was out of order for me. Instead, Modify your database connection configuration in your apps settings.py file. As outlined in step 8 here.
- Then, start to test the app as advised, and everything should go just fine.
Comments
Post a Comment
Please leave your comments on this topic: