Connecting Django to different Database
Django comes built-in with the SQLite database. We can also see this in the DATABASES dictionary in our settings.py file.
Python3
DATABASES = { 'default' : { 'ENGINE' : 'django.db.backends.sqlite3' , 'NAME' : BASE_DIR / 'db.sqlite3' , } } |
If you want to change this to another database you can change the above dictionary. Let’s suppose we want to change this database to PostgreSQL. Assuming the required dependencies are installed and the PostgreSQL is set up then the DATABASES dictionary will look like –
Python3
DATABASES = { 'default' : { 'ENGINE' : 'django.db.backends.postgresql' , 'NAME' : ‘<database_name>’, 'USER' : '<database_username>' , 'PASSWORD' : '<password>' , 'HOST' : '<database_hostname_or_ip>' , 'PORT' : '<database_port>' , } } |
Refer to the below articles to get more information about connecting Django to different databases –
Python Web Development With Django
Python Django is a web framework that allows to quickly create efficient web pages. Django is also called batteries included framework because it provides built-in features such as Django Admin Interface, default database – SQLite3, etc. When you’re building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc. Django gives you ready-made components to use.