django psql setup

Solutions on MaxInterview for django psql setup by the best coders in the world

showing results for - "django psql setup"
Viktoria
23 May 2019
1This gist I write, because I couldn't find step by step instructions 
2how to install and start postgresql locally and not globally in the
3operating system (which would require sudo).
4
5I hope, this will help especially people new to postgresql!
6
7####################################
8# create conda environment
9####################################
10
11conda create --name myenv
12
13# enter the environment
14conda activate myenv
15
16####################################
17# install postgresql via conda
18####################################
19
20conda install -y -c conda-forge postgresql
21
22####################################
23# create a base database locally
24####################################
25
26initdb -D mylocal_db
27
28##############################
29# now start the server modus/instance of postgres
30##############################
31
32pg_ctl -D mylocal_db -l logfile start
33
34## waiting for server to start.... done
35## server started
36
37# now the server is up
38
39
40####################################
41# create a non-superuser (more safety!)
42####################################
43
44createuser --encrypted --pwprompt mynonsuperuser
45# asks for name and password
46
47####################################
48# using this super user, create inner database inside the base database
49####################################
50
51createdb --owner=mynonsuperuser myinner_db
52
53
54####################################
55# in this point, if you run some program,
56# you connect you program with this inner database
57# e.g. Django 
58####################################
59
60# in django (Python) e.g. you do
61
62nano <mysite>/settings.py # or instead of nano your favorite editor!
63
64DATABASES = {
65    'default': {
66        'ENGINE': 'django.db.backends.postgresql',
67        'NAME': 'myinner_db',
68        'USER': 'mynonsuperuser',
69        'PASSWORD': '<mynonsuperuserpassword>',
70        'HOST': 'localhost',
71        'PORT': '',
72    }
73}
74
75
76
77
78# and it is available for django
79# so that you can do
80
81##############################
82# do with the connected program further steps
83##############################
84
85# first install psycopg2
86# because django requires this for handling postgresql
87conda install -c anaconda psycopg2