From 6e04c865bd475258585fd68c63f8b36a7d327061 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 4 Mar 2018 10:27:32 +0100 Subject: [PATCH] Allow connection to database url --- Pipfile | 4 ++- Pipfile.lock | 72 +++++++++++++++++++++++++++------------------ manage.py | 3 ++ workout/settings.py | 7 ++--- 4 files changed, 52 insertions(+), 34 deletions(-) diff --git a/Pipfile b/Pipfile index a8cca85..36c0d38 100644 --- a/Pipfile +++ b/Pipfile @@ -10,8 +10,10 @@ name = "pypi" django = "*" djangorestframework = "*" "django-bootstrap4" = "*" -"psycopg2" = "*" gunicorn = "*" +dj-database-url = "*" +"psycopg2-binary" = "*" +django-dotenv = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 8c8e81c..f396d23 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d7ae749ff4abfae378899b6f2a6d3e182673cb7b2dcd4f90b48c0156b4786199" + "sha256": "22b4bfbc1d497b2f1f362b483254e91ae7164879bf4c072932b36e9f9bbe91b9" }, "host-environment-markers": { "implementation_name": "cpython", @@ -27,6 +27,13 @@ ] }, "default": { + "dj-database-url": { + "hashes": [ + "sha256:851785365761ebe4994a921b433062309eb882fedd318e1b0fcecc607ed02da9", + "sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163" + ], + "version": "==0.5.0" + }, "django": { "hashes": [ "sha256:7c8ff92285406fb349e765e9ade685eec7271d6f5c3f918e495a74768b765c99", @@ -40,6 +47,13 @@ ], "version": "==0.0.6" }, + "django-dotenv": { + "hashes": [ + "sha256:a9b1b40a70bd321acd231926acedb9bd2c5e873e33a1873b34a7276d196a765e", + "sha256:3812bb0f4876cf31f902aad140f0645e120e51ee30eb7c40c22050f58a0e4adb" + ], + "version": "==1.4.2" + }, "djangorestframework": { "hashes": [ "sha256:1f6baf40ed456ed2af6bd1a4ff8bbc3503cebea16509993aea2b7085bc097766", @@ -54,35 +68,35 @@ ], "version": "==19.7.1" }, - "psycopg2": { + "psycopg2-binary": { "hashes": [ - "sha256:aeaba399254ca79c299d9fe6aa811d3c3eac61458dee10270de7f4e71c624998", - "sha256:1d90379d01d0dc50ae9b40c863933d87ff82d51dd7d52cea5d1cb7019afd72cd", - "sha256:36030ca7f4b4519ee4f52a74edc4ec73c75abfb6ea1d80ac7480953d1c0aa3c3", - "sha256:7cbc3b21ce2f681ca9ad2d8c0901090b23a30c955e980ebf1006d41f37068a95", - "sha256:b178e0923c93393e16646155794521e063ec17b7cc9f943f15b7d4b39776ea2c", - "sha256:fe6a7f87356116f5ea840c65b032af17deef0e1a5c34013a2962dd6f99b860dd", - "sha256:6f302c486132f8dd11f143e919e236ea4467d53bf18c451cac577e6988ecbd05", - "sha256:888bba7841116e529f407f15c6d28fe3ef0760df8c45257442ec2f14f161c871", - "sha256:932a4c101af007cb3132b1f8a9ffef23386acc53dad46536dc5ba43a3235ae02", - "sha256:179c52eb870110a8c1b460c86d4f696d58510ea025602cd3f81453746fccb94f", - "sha256:33f9e1032095e1436fa9ec424abcbd4c170da934fb70e391c5d78275d0307c75", - "sha256:092a80da1b052a181b6e6c765849c9b32d46c5dac3b81bf8c9b83e697f3cdbe8", - "sha256:f3d3a88128f0c219bdc5b2d9ccd496517199660cea021c560a3252116df91cbd", - "sha256:19983b77ec1fc2a210092aa0333ee48811fd9fb5f194c6cd5b927ed409aea5f8", - "sha256:027ae518d0e3b8fff41990e598bc7774c3d08a3a20e9ecc0b59fb2aaaf152f7f", - "sha256:363fbbf4189722fc46779be1fad2597e2c40b3f577dc618f353a46391cf5d235", - "sha256:d74cf9234ba76426add5e123449be08993a9b13ff434c6efa3a07caa305a619f", - "sha256:32702e3bd8bfe12b36226ba9846ed9e22336fc4bd710039d594b36bd432ae255", - "sha256:8eb94c0625c529215b53c08fb4e461546e2f3fc96a49c13d5474b5ad7aeab6cf", - "sha256:8ebba5314c609a05c6955e5773c7e0e57b8dd817e4f751f30de729be58fa5e78", - "sha256:27467fd5af1dcc0a82d72927113b8f92da8f44b2efbdb8906bd76face95b596d", - "sha256:b68e89bb086a9476fa85298caab43f92d0a6af135a5f433d1f6b6d82cafa7b55", - "sha256:0b9851e798bae024ed1a2a6377a8dab4b8a128a56ed406f572f9f06194e4b275", - "sha256:733166464598c239323142c071fa4c9b91c14359176e5ae7e202db6bcc1d2eb5", - "sha256:ad75fe10bea19ad2188c5cb5fc4cdf53ee808d9b44578c94a3cd1e9fc2beb656", - "sha256:8966829cb0d21a08a3c5ac971a2eb67c3927ae27c247300a8476554cc0ce2ae8", - "sha256:8bf51191d60f6987482ef0cfe8511bbf4877a5aa7f313d7b488b53189cf26209" + "sha256:b287ddf4cafcfb632974907d1e7862119e36bb758228bdb07dd247553e4cdfc0", + "sha256:d1dd3eb8edd354083f5d27b968c5a17854c41347ba5a480b520be85ec1a8495c", + "sha256:cf3911fba0c47fc1313b5783183cda301032b14637a0b7a336766ae46998c7ee", + "sha256:b039f51bca1ddd70234cc3f84f94f42ad43861b931bdfb497f887c60c39a6565", + "sha256:83af04029bcb4b56c852e5876fef71340dcb465fa44fc99f80bac72e10fb0b74", + "sha256:3a14baeabcebd4662f12f4bff03e0574a2369a2e41baf829e6fb4a24c95cf88b", + "sha256:cb07184a4bfad304831f0a88b1c13fbd8cf9fcdf1f11e71c477dd6d7b1b078a0", + "sha256:d0972f062c73956332e9681dfdb133168618f0abfecc96e89f0205ac89cd454b", + "sha256:ab1db8f3e96570d9f7ebc45133ce2574804b2280499baade178e163d022107b5", + "sha256:d51c7ed810fce1e50464088c37cc8da05534de8afb12a732500827ebcc480081", + "sha256:b6b2b26590304d97ef2af28d153ee99ace6fe0806934f4618edfc87216c77f91", + "sha256:9b5ddbed85ec73293695d7116589d956ef0dd3fcf7bf3b2a3bc1e8e54c1d543a", + "sha256:02eb674e3d5810e19b4d5d00720b17130e182da1ba259dda608aaf33d787347d", + "sha256:436a503eda41f6adb08f292f40a3784fce0a5f351b6ae7b19a911904db53af93", + "sha256:8014c06a9ed7b78ba81beff3ae71acd78c212390f8ed839e9ce22735880bd5b4", + "sha256:c4c6004d410c77bfa5389ae9485498ce32805447a67afbfe8db0d247a5c88fa1", + "sha256:d8940b5104588d6313315e037f0f5ed68d2e5f62ccc1c429d3cff11d2ba6de3f", + "sha256:c606bff0978ee4858d86d40f6b6ab0c4cac4474f627bd054683dc03a4fc1a366", + "sha256:9305d7cbc802aaefac5c75a3df725f2654797369f32b18d4d0adb382dfab6c09", + "sha256:4a1a5ea2fa4b53191637b162873a82822d92a85a08beefe28296b8eb5cf2fea5", + "sha256:a3d2cc0cb0b988dbfd0d11f7fac34058b25a6ce533ed5b8e88d6cb315e77d54a", + "sha256:86c0d2587f56776f25d52cca8e275adf495c8e01933fbfc2ca23b124610ab761", + "sha256:77a2fc622a1f2d08a707673c9be5769d521f03d867d305f172bb417fa7882754", + "sha256:4a4f23a08fbccbe40ecdb5384d807bcb469ea71dd87e6be2e80b036b8e6d47df", + "sha256:c8220c521a408b41c4f14036004a621ed0d965941286b978cd2ea2623fabd755", + "sha256:465ff1d427ed42c31e456dbbd9edab3552be18a0edaef7450c5b3e6fee745052", + "sha256:de4f88f823037a71ea5ef3c1041d96b8a68d73343133edda684fd42f575bd9d7" ], "version": "==2.7.4" }, diff --git a/manage.py b/manage.py index 5976a21..3f6b404 100755 --- a/manage.py +++ b/manage.py @@ -2,7 +2,10 @@ import os import sys +import dotenv + if __name__ == "__main__": + dotenv.read_dotenv() os.environ.setdefault("DJANGO_SETTINGS_MODULE", "workout.settings") try: from django.core.management import execute_from_command_line diff --git a/workout/settings.py b/workout/settings.py index 01e7478..e1b205c 100644 --- a/workout/settings.py +++ b/workout/settings.py @@ -13,6 +13,8 @@ https://docs.djangoproject.com/en/2.0/ref/settings/ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import dj_database_url + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production @@ -74,10 +76,7 @@ WSGI_APPLICATION = 'workout.wsgi.application' # https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } + 'default': dj_database_url.config(default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3'), conn_max_age=600) } # Password validation