Find the location of data base file that gets created when a user is created in django application

10/11/2019

In a Django application with PostgreSQL as database, where do the users get stored? Any file where can I check the users info...basically where will be the .db file stored in Django?

-- Lisa
django
kubernetes
postgresql

2 Answers

10/11/2019

In the settings.py file, there is a variable called DATABASES. It is a dict, and one of its keys is default, which maps to another dict. This subdict has a key, NAME, which has the path of the database.

This is an example of a project

CURRENT_DIR= '/path/'
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.db',
        'NAME': CURRENT_DIR+ '/database.db', # <- The path
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}
-- sa_n__u
Source: StackOverflow

10/15/2019

The default location for storage in PostgreSQL is /var/lib/postgresql/data. Kubernetes provides the Secret object to store sensitive data, which can be created using i.e. the declarative file specification.

apiVersion: v1
kind: Secret
metadata:
  name: postgres-credentials
type: Opaque
data:
  user: ZGphbmdv
  password: MWEyNmQxZzI2ZDFnZXNiP2U3ZGVzYj9lN2Q=

User field as well as password field contains base64 encoded strings where the encoding can be generated from the command line by running:

$ echo -n "<string>" | base64

The Secret object is then added to the kubernetes cluster using:

$ kubectl apply -f postgres/secrets.yaml

By default, Django uses the sqlite database configuration. To update the database configuration, the following modifications needs to be made to the DATABASES variable in the settings.py file. Please refer to documentation.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'kubernetes_django',
        'USER': os.getenv('POSTGRES_USER'),
        'PASSWORD': os.getenv('POSTGRES_PASSWORD'),
        'HOST': os.getenv('POSTGRES_HOST'),
        'PORT': os.getenv('POSTGRES_PORT', 5432)
     }
}

I hope it will helps you.

-- muscat
Source: StackOverflow