Install Python, follow the steps here.
Steps I take when beginning a new Django project.
$ mkdir [project_name]_project
$ cd [project_name]_project
$ ~/local/python-3.5.1/bin/pyvenv env
$ . env/bin/activate
$ pip install django
$ pip freeze > requirements.txt
$ django-admin startproject [project_name]
$ touch .gitignoreContents of the .gitignore file.
db.sqlite3
env
*.pyc
Before making anymore changes test that it works and then put everything under version control.
# Test it out
$ cd [project_name]
$ python manage.py migrate
$ python manage.py runserver
# View the site at http://127.0.0.1:8000/
# Version it
$ git init
$ git add --all
$ git commit -m "Initial commit"Now change the database and timezone settings in [project_name]_project/[project_name]/[project_name]/settings.py.
Prerequisites
- Install
psycopg2with$ pip install psycopg2. See here for more details. - Create the database in PostgreSQL, say
[project_name]_development, with$ createdb -O [user] [project_name]_development.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '[project_name]_development',
'USER': '[user]',
'PASSWORD': '********',
'HOST': 'localhost',
'PORT': '5432'
}
}
TIME_ZONE = 'America/Port_of_Spain'Tip: If you want to connect without specifying a user and password then use the following setting.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '[project_name]_development'
}
}Without specifying a HOST psycopg2 will connect using a Unix socket in the same manner as psql. When you specify a HOST, psycopg2 will connect with TCP/IP, which requires a password. (ref)
Now, we can migrate the db, create a super user, start the server and view the admin page to see that everything was set up correctly.
$ python manage.py migrate
$ python manage.py createsuperuser
$ python manage.py runserverView the admin page at http://localhost:8000/admin.
Update your requirements.txt file and finally commit your changes at this point.
$ pip freeze > requirements.txt
$ git add --all
$ git commit -m "Configure a PostgreSQL database and set the timezone"