Skip to content

Commit

Permalink
Extraido a URL do banco de dados com dj-database-url
Browse files Browse the repository at this point in the history
close #32
  • Loading branch information
thiago-garcia committed Mar 27, 2024
1 parent fcd8e5b commit 5f547a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ django = "*"
gunicorn = "*"
pytest-django = "*"
python-decouple = "*"
dj-database-url = "*"

[dev-packages]
flake8 = "*"
Expand Down
12 changes: 10 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions pypro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"""

from pathlib import Path

from decouple import config, Csv
import dj_database_url
from functools import partial

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -76,11 +77,12 @@
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

default_db_url = 'sqlite:///' + str(BASE_DIR / 'db.sqlite3')

parse_database = partial(dj_database_url.parse, conn_max_age=600)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
'default': config('DATABASE_URL', default=default_db_url, cast=parse_database)
}


Expand Down

0 comments on commit 5f547a4

Please sign in to comment.