Django App - Database connection

29 views
Skip to first unread message

Sapna Dhage

unread,
Jun 14, 2019, 11:15:51 AM6/14/19
to Django users

Hello,

I'm implementing Django application using PostgreSQL. However, I'm not able to configure database connection string.

Any idea how do I configure database connection and where should I mention database connection string?

Thank you,
Sapna

Sipum Mishra

unread,
Jun 14, 2019, 1:08:08 PM6/14/19
to django...@googlegroups.com
Hi sapna,

Check your settings.py file and search for DATABASE there you can get a link which is commented. Copy n paste that url and that will take you to documentation page where you can get what needs to be imported in DATABASE. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/35a7d002-cf8a-4924-8b8b-9df35419b1f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Edwards

unread,
Jun 14, 2019, 2:22:18 PM6/14/19
to django...@googlegroups.com
These are the settings to use in settings.py:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB-NAME',
'USER': 'USER',
'PASSWORD':'PASSWORD',
'HOST':'HOST',
'PORT': 'PORT',
'OPTIONS': {'charset': 'utf8'}

}
}
Dave Edwards
------------------------

Email   > Da...@DWEDigital.com 
Mobile > 07788275564 

DWE Digital Ltd. Registered in Jersey, Channel Islands
Company Registration Number: 116942
---
This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Any dissemination, distribution or copying of this message or any files transmitted with it by an unauthorised recipient is strictly prohibited. 


Dave Edwards

unread,
Jun 14, 2019, 2:22:18 PM6/14/19
to django...@googlegroups.com
Apologies that was from when I used MySQL, please use the following for postgres:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST':'HOST',
'PORT':'PORT',
'USER':'USERNAME',
'PASSWORD':'PASSWORD',
'NAME': 'DATABASE NAME',
}
}
Dave Edwards
------------------------

Email   > Da...@DWEDigital.com 
Mobile > 07788275564 

DWE Digital Ltd. Registered in Jersey, Channel Islands
Company Registration Number: 116942
---
This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Any dissemination, distribution or copying of this message or any files transmitted with it by an unauthorised recipient is strictly prohibited. 

Ing.Daniel Bojorge

unread,
Jun 14, 2019, 5:15:27 PM6/14/19
to django...@googlegroups.com
You can use psycopg2

then in your settings must have something like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': DATABASENAME,
        'USER': YOURUSER,
        'PASSWORD': YOURPASSWORD,
        'HOST': SERVER,
        'PORT': PORT,
    }
}

You can found more in my blog (in spanish) https://debsconsultores.blogspot.com



Mi Blog
Nicaragua

"Si ustedes permanecen unidos a mí, y si permanecen fieles a mis enseñanzas, pidan lo que quieran y se les dará.
(Juan 15:7 DHH)
Bendito el varón que se fía en el SEÑOR, y cuya confianza es el SEÑOR.
(Jeremías 17:7 RV2000)



Travis Risner

unread,
Jun 17, 2019, 12:03:27 AM6/17/19
to django...@googlegroups.com
Hi Sapna,

What works for me (in Django 2.2) is to use the ENGINE setting that Dave
suggested:

'ENGINE':'django.db.backends.postgresql',

and install the driver that Daniel suggested:

psycopg2

Some database drivers are in the standard Python library (e.g. sqlite)
while others need to be installed in the virtual environment.

Recently, the psycopg2 library was split into two parts.

psycopg2 - has the source code for this library
psycopg2-binary - has binaries for various platforms

It may only be necessary to install psycopg2-binary to get Django to
work with PostgreSQL. The first library seems to require lots of
support in the OS for pip to install.

HTH,
Travis

Ing.Daniel Bojorge wrote on 6/14/19 1:14 PM:
> You can use psycopg2
>
> then in your settings must have something like this:
>
> DATABASES = {
>     'default': {
>         'ENGINE': 'django.db.backends.postgresql_psycopg2',
>         'NAME': DATABASENAME,
>         'USER': YOURUSER,
>         'PASSWORD': YOURPASSWORD,
>         'HOST': SERVER,
>         'PORT': PORT,
>     }
> }
>
> You can found more in my blog (in spanish)
> https://debsconsultores.blogspot.com <https://debsconsultores.blogspot.com/>
>
>
>
> Dios L@s Bendiga
>
> Saludos,
>
> --
>
> daniel.bojorge
> http://about.me/daniel.bojorge
>
> <http://about.me/daniel.bojorge?promo=email_sig>
>
> *Curso Desarrollo Web con Python usando Django 2.1 Para Principiantes*
> <https://goo.gl/oeT5Sx>
> *WebService RestFul API con Python usando Django RestFrameWork*
> <https://goo.gl/j8i34C>
> *Fácil Replicación de Cualquier Base de Datos y/o Sistema Operativo*
> <https://goo.gl/HjtExs>
> *Programación en Capas (Web y Escritorio)* <https://goo.gl/zGZpSD>
> Mi Blog <http://debsconsultores.blogspot.com>
> Nicaragua
>
> "Si ustedes permanecen unidos a mí, y si permanecen fieles a mis
> enseñanzas, pidan lo que quieran y se les dará.
> (Juan 15:7 DHH)
> Bendito el varón que se fía en el SEÑOR, y cuya confianza es el SEÑOR.
> (Jeremías 17:7 RV2000)
>
>
>
> El vie., 14 jun. 2019 a las 8:22, Dave Edwards (<da...@dwedigital.com
> <mailto:da...@dwedigital.com>>) escribió:
>
> Apologies that was from when I used MySQL, please use the following
> for postgres:
>
> DATABASES={
> 'default':{
> 'ENGINE':'django.db.backends.postgresql',
> 'HOST':'HOST',
> 'PORT':'PORT',
> 'USER':'USERNAME',
> 'PASSWORD':'PASSWORD',
> 'NAME':'DATABASE NAME',
> }
> }
> *Dave Edwards*
> ------------------------
>
> Email**>Da...@DWEDigital.com
> Mobile**> 07788275564
> Online**>www.dwedigital.com <http://www.dwedigital.com/>
>
> DWE Digital Ltd. Registered in Jersey, Channel Islands
> Company Registration Number: 116942
> ---
> This e-mail and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. Any dissemination, distribution or copying of this
> message or any files transmitted with it by an unauthorised
> recipient is strictly prohibited.
>
>
> On Fri, 14 Jun 2019 at 14:21, Dave Edwards <da...@dwedigital.com
> <mailto:da...@dwedigital.com>> wrote:
>
> These are the settings to use in settings.py:
>
> DATABASES={
> 'default':{
> 'ENGINE':'django.db.backends.mysql',
> 'NAME':'DB-NAME',
> 'USER':'USER',
> 'PASSWORD':'PASSWORD',
> 'HOST':'HOST',
> 'PORT':'PORT',
> 'OPTIONS':{'charset':'utf8'}
>
> }
> }
> *Dave Edwards*
> ------------------------
>
> Email**>Da...@DWEDigital.com
> Mobile**> 07788275564
> Online**>www.dwedigital.com <http://www.dwedigital.com/>
>
> DWE Digital Ltd. Registered in Jersey, Channel Islands
> Company Registration Number: 116942
> ---
> This e-mail and any files transmitted with it are confidential
> and intended solely for the use of the individual or entity to
> whom they are addressed. Any dissemination, distribution or
> copying of this message or any files transmitted with it by an
> unauthorised recipient is strictly prohibited.
>
>
> On Fri, 14 Jun 2019 at 14:08, Sipum Mishra <sip...@gmail.com
> <mailto:sip...@gmail.com>> wrote:
>
> Hi sapna,
>
> Check your settings.py file and search for DATABASE there
> you can get a link which is commented. Copy n paste that url
> and that will take you to documentation page where you can
> get what needs to be imported in DATABASE.
>
> On Fri, 14 Jun, 2019, 4:45 PM Sapna Dhage,
> <sapna...@gmail.com <mailto:sapna...@gmail.com>> wrote:
>
>
> Hello,
>
> I'm implementing Django application using PostgreSQL.
> However, I'm not able to configure database connection
> string.
>
> Any idea how do I configure database connection and
> where should I mention database connection string?
>
> Thank you,
> Sapna
>
> --

[snip]
Reply all
Reply to author
Forward
0 new messages