From 2e849e47797d6a16a198bd0f8a30b469d6a46b61 Mon Sep 17 00:00:00 2001 From: zaqbez39me Date: Sat, 2 Jul 2022 22:16:57 +0300 Subject: [PATCH 1/8] Deploy on heroku --- Procfile | 1 + docToPdf/settings.py | 17 ++++++++--------- requirements.txt | 36 ++++++++++++++++++++++++++++++++---- runtime.txt | 1 + 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 Procfile create mode 100644 runtime.txt diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..07f3a00 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn docToPdf.wsgi --log-file - \ No newline at end of file diff --git a/docToPdf/settings.py b/docToPdf/settings.py index dacbb4e..e1703c2 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -9,9 +9,13 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.0/ref/settings/ """ - +import os from pathlib import Path +import dj_database_url + +db_from_env = dj_database_url.config() + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -24,10 +28,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [ - 'localhost', - '127.0.0.1', -] +ALLOWED_HOSTS = ['*'] DATA_UPLOAD_MAX_NUMBER_FIELDS = None # Application definition @@ -78,10 +79,7 @@ # https://docs.djangoproject.com/en/4.0/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } + 'default': db_from_env } REST_FRAMEWORK = { @@ -125,6 +123,7 @@ # https://docs.djangoproject.com/en/4.0/howto/static-files/ STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field diff --git a/requirements.txt b/requirements.txt index d5025ac..ebad9a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,35 @@ Django djangorestframework -pywin32; platform_system == "Windows" -docx2pdf; platform_system == "Windows" +pywin32==304; platform_system == "Windows" +docx2pdf==0.1.8; platform_system == "Windows" +dj-database-url==0.5.0 requests==2.28.1 -sphinx -coverage \ No newline at end of file +Sphinx==5.0.2 +coverage +alabaster==0.7.12 +asgiref==3.5.2 +Babel==2.10.3 +certifi==2022.6.15 +charset-normalizer==2.1.0 +colorama==0.4.5 +psycopg2 +docutils==0.18.1 +idna==3.3 +imagesize==1.4.1 +Jinja2==3.1.2 +MarkupSafe==2.1.1 +packaging==21.3 +Pygments==2.12.0 +pyparsing==3.0.9 +pytz==2022.1 +snowballstemmer==2.2.0 +sphinxcontrib-applehelp==1.0.2 +sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-htmlhelp==2.0.0 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-serializinghtml==1.1.5 +sqlparse==0.4.2 +tqdm==4.64.0 +tzdata==2022.1 +urllib3==1.26.9 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..4fb51b0 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.10.5 \ No newline at end of file From 892ca651df6dfa14d45635748f37571963d29b10 Mon Sep 17 00:00:00 2001 From: osx11 Date: Sat, 2 Jul 2022 22:28:20 +0300 Subject: [PATCH 2/8] defined static root and static url --- docToPdf/settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docToPdf/settings.py b/docToPdf/settings.py index dacbb4e..e571fd3 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -10,6 +10,8 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ """ +import os + from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -124,7 +126,8 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ -STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, "main/static/") +STATIC_URL = '/static/' # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field From a671eca921a065595db62b2fff1abc9fc3001fbe Mon Sep 17 00:00:00 2001 From: osx11 Date: Sat, 2 Jul 2022 22:32:00 +0300 Subject: [PATCH 3/8] fixed imports for linter --- docToPdf/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docToPdf/settings.py b/docToPdf/settings.py index e571fd3..7783a55 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -10,10 +10,10 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ """ -import os - from pathlib import Path +import os + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent From eb126669021c683e5edc13a3e031ea69f6d5b633 Mon Sep 17 00:00:00 2001 From: osx11 Date: Sat, 2 Jul 2022 22:44:32 +0300 Subject: [PATCH 4/8] trying to change base_dir to deploy to heroku --- docToPdf/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docToPdf/settings.py b/docToPdf/settings.py index 7783a55..c737932 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -15,7 +15,7 @@ import os # Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ @@ -82,7 +82,7 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } From d883d96a8b78fb929b144a0196011b3a1baf05af Mon Sep 17 00:00:00 2001 From: osx11 Date: Sat, 2 Jul 2022 22:51:04 +0300 Subject: [PATCH 5/8] fixed imports for linter --- docToPdf/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docToPdf/settings.py b/docToPdf/settings.py index c737932..8d72c85 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -10,9 +10,9 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ """ +import os from pathlib import Path -import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) From ac90464f5d4f37a3a7f79ceed099dba934502c04 Mon Sep 17 00:00:00 2001 From: osx11 Date: Sat, 2 Jul 2022 22:54:54 +0300 Subject: [PATCH 6/8] fixed imports for linter --- docToPdf/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docToPdf/settings.py b/docToPdf/settings.py index 8d72c85..147b8c2 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -13,7 +13,6 @@ import os from pathlib import Path - # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) From 44e6532c02d237c1a8125ec7b0ec51c3e897279e Mon Sep 17 00:00:00 2001 From: zaqbez39me Date: Sat, 2 Jul 2022 22:59:40 +0300 Subject: [PATCH 7/8] Fixed for heroku --- docToPdf/settings.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docToPdf/settings.py b/docToPdf/settings.py index 147b8c2..a2632a0 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -13,6 +13,10 @@ import os from pathlib import Path +import dj_database_url + +db_from_env = dj_database_url.config() + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -25,10 +29,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [ - 'localhost', - '127.0.0.1', -] +ALLOWED_HOSTS = ['*'] DATA_UPLOAD_MAX_NUMBER_FIELDS = None # Application definition @@ -79,10 +80,7 @@ # https://docs.djangoproject.com/en/4.0/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } + 'default': db_from_env } REST_FRAMEWORK = { From 90fa518ddccb2027e8c7d48fd9898b487fbbc199 Mon Sep 17 00:00:00 2001 From: zaqbez39me Date: Sat, 2 Jul 2022 23:20:26 +0300 Subject: [PATCH 8/8] changed settings --- docToPdf/settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docToPdf/settings.py b/docToPdf/settings.py index 9d9996f..ca6cf40 100644 --- a/docToPdf/settings.py +++ b/docToPdf/settings.py @@ -53,6 +53,8 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", ] ROOT_URLCONF = 'docToPdf.urls' @@ -125,7 +127,8 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ -STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') +STATIC_URL = '/static/' # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field