From bde3ad88bfe3c7a9808ff0e29c43fae3c24a671f Mon Sep 17 00:00:00 2001 From: Dezik Date: Wed, 17 Dec 2025 19:44:36 +0100 Subject: [PATCH 01/10] fix allowed hosts --- gettingstarted/settings.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index a4d5cf55b..c206be8b0 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -44,20 +44,26 @@ # Debug mode will be automatically enabled when the project is run via `heroku local` (which # loads the environment variables set in the `.env` file, where `ENVIRONMENT=development`). # SECURITY WARNING: Don't run with debug turned on in production! -DEBUG = os.environ.get("ENVIRONMENT") == "development" +DEBUG = True # The `DYNO` env var is set on Heroku CI, but it's not a real Heroku app, so we have to # also explicitly exclude CI: # https://devcenter.heroku.com/articles/heroku-ci#immutable-environment-variables IS_HEROKU_APP = "DYNO" in os.environ and "CI" not in os.environ - +# Zawsze bazowa lista hostów (lokalnie + Render) +ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'https://python-getting-started-lab1-lk4l.onrender.com'] +# Jeśli używasz Heroku i chcesz wildcard, możesz opcjonalnie rozszerzyć: +if os.environ.get('IS_HEROKU_APP') == '1': +ALLOWED_HOSTS.append('*') +# Dynamicznie z env (dla przyszłości, np. ALLOWED_HOSTS z Render) +if os.environ.get('ALLOWED_HOSTS'): +ALLOWED_HOSTS.extend(os.environ.get('ALLOWED_HOSTS').split(',')) if IS_HEROKU_APP: - # On Heroku, it's safe to use a wildcard for `ALLOWED_HOSTS`, since the Heroku router performs - # validation of the Host header in the incoming HTTP request. On other platforms you may need to - # list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See: - # https://docs.djangoproject.com/en/6.0/ref/settings/#std-setting-ALLOWED_HOSTS - ALLOWED_HOSTS = ["*"] - +# On Heroku, it's safe to use a wildcard for `ALLOWED_HOSTS`, since the Heroku router performs +# validation of the Host header in the incoming HTTP request. On other platforms you may need to +# list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See: +# https://docs.djangoproject.com/en/6.0/ref/settings/#std-setting-ALLOWED_HOSTS +#ALLOWED_HOSTS = ["*"] # Redirect all non-HTTPS requests to HTTPS. This requires that: # 1. Your app has a TLS/SSL certificate, which all `*.herokuapp.com` domains do by default. # When using a custom domain, you must configure one. See: From 5b046b74fa7459e2dd2a2c113dbe162e7ceb6a3b Mon Sep 17 00:00:00 2001 From: Dezik Date: Thu, 18 Dec 2025 16:08:47 +0100 Subject: [PATCH 02/10] dasda --- gettingstarted/settings.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index c206be8b0..2295befa4 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -54,16 +54,17 @@ ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'https://python-getting-started-lab1-lk4l.onrender.com'] # Jeśli używasz Heroku i chcesz wildcard, możesz opcjonalnie rozszerzyć: if os.environ.get('IS_HEROKU_APP') == '1': -ALLOWED_HOSTS.append('*') -# Dynamicznie z env (dla przyszłości, np. ALLOWED_HOSTS z Render) + ALLOWED_HOSTS.append('*') + # Dynamicznie z env (dla przyszłości, np. ALLOWED_HOSTS z Render) if os.environ.get('ALLOWED_HOSTS'): -ALLOWED_HOSTS.extend(os.environ.get('ALLOWED_HOSTS').split(',')) + ALLOWED_HOSTS.extend(os.environ.get('ALLOWED_HOSTS').split(',')) if IS_HEROKU_APP: -# On Heroku, it's safe to use a wildcard for `ALLOWED_HOSTS`, since the Heroku router performs -# validation of the Host header in the incoming HTTP request. On other platforms you may need to -# list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See: -# https://docs.djangoproject.com/en/6.0/ref/settings/#std-setting-ALLOWED_HOSTS -#ALLOWED_HOSTS = ["*"] + # On Heroku, it's safe to use a wildcard for `ALLOWED_HOSTS`, since the Heroku router performs + # validation of the Host header in the incoming HTTP request. On other platforms you may need to + # list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See: + # https://docs.djangoproject.com/en/6.0/ref/settings/#std-setting-ALLOWED_HOSTS + #ALLOWED_HOSTS = ["*"] + # Redirect all non-HTTPS requests to HTTPS. This requires that: # 1. Your app has a TLS/SSL certificate, which all `*.herokuapp.com` domains do by default. # When using a custom domain, you must configure one. See: @@ -250,4 +251,4 @@ "level": "ERROR", }, }, -} +} \ No newline at end of file From bb6b0b2b6137544f07dbd7ab9250538025f01980 Mon Sep 17 00:00:00 2001 From: Dezik Date: Thu, 18 Dec 2025 16:17:00 +0100 Subject: [PATCH 03/10] dasdaa --- gettingstarted/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index 2295befa4..2c799761b 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -51,7 +51,7 @@ # https://devcenter.heroku.com/articles/heroku-ci#immutable-environment-variables IS_HEROKU_APP = "DYNO" in os.environ and "CI" not in os.environ # Zawsze bazowa lista hostów (lokalnie + Render) -ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'https://python-getting-started-lab1-lk4l.onrender.com'] +ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'python-getting-started-lab1-lk4l.onrender.com' , 'https://python-getting-started-lab1-lk4l.onrender.com/'] # Jeśli używasz Heroku i chcesz wildcard, możesz opcjonalnie rozszerzyć: if os.environ.get('IS_HEROKU_APP') == '1': ALLOWED_HOSTS.append('*') From 7fe22d509cda40dbd6d88cf54bbf97e7bce0777e Mon Sep 17 00:00:00 2001 From: Dezik Date: Thu, 18 Dec 2025 16:27:13 +0100 Subject: [PATCH 04/10] dasdaa --- gettingstarted/settings.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index 2c799761b..7e67973e7 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -44,26 +44,19 @@ # Debug mode will be automatically enabled when the project is run via `heroku local` (which # loads the environment variables set in the `.env` file, where `ENVIRONMENT=development`). # SECURITY WARNING: Don't run with debug turned on in production! -DEBUG = True +DEBUG = os.environ.get("ENVIRONMENT") == "development" # The `DYNO` env var is set on Heroku CI, but it's not a real Heroku app, so we have to # also explicitly exclude CI: # https://devcenter.heroku.com/articles/heroku-ci#immutable-environment-variables IS_HEROKU_APP = "DYNO" in os.environ and "CI" not in os.environ -# Zawsze bazowa lista hostów (lokalnie + Render) -ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'python-getting-started-lab1-lk4l.onrender.com' , 'https://python-getting-started-lab1-lk4l.onrender.com/'] -# Jeśli używasz Heroku i chcesz wildcard, możesz opcjonalnie rozszerzyć: -if os.environ.get('IS_HEROKU_APP') == '1': - ALLOWED_HOSTS.append('*') - # Dynamicznie z env (dla przyszłości, np. ALLOWED_HOSTS z Render) -if os.environ.get('ALLOWED_HOSTS'): - ALLOWED_HOSTS.extend(os.environ.get('ALLOWED_HOSTS').split(',')) + if IS_HEROKU_APP: # On Heroku, it's safe to use a wildcard for `ALLOWED_HOSTS`, since the Heroku router performs # validation of the Host header in the incoming HTTP request. On other platforms you may need to # list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See: # https://docs.djangoproject.com/en/6.0/ref/settings/#std-setting-ALLOWED_HOSTS - #ALLOWED_HOSTS = ["*"] + ALLOWED_HOSTS = ["*"] # Redirect all non-HTTPS requests to HTTPS. This requires that: # 1. Your app has a TLS/SSL certificate, which all `*.herokuapp.com` domains do by default. @@ -77,7 +70,7 @@ # https://docs.djangoproject.com/en/6.0/ref/middleware/#http-strict-transport-security SECURE_SSL_REDIRECT = True else: - ALLOWED_HOSTS = [".localhost", "127.0.0.1", "[::1]", "0.0.0.0", "[::]"] + ALLOWED_HOSTS = ["*"] # Application definition @@ -251,4 +244,4 @@ "level": "ERROR", }, }, -} \ No newline at end of file +} From b92d7c81a4b06b48074030467441f48914980ded Mon Sep 17 00:00:00 2001 From: Dezik Date: Thu, 18 Dec 2025 16:38:44 +0100 Subject: [PATCH 05/10] asd --- gettingstarted/settings.py | 10 +++++----- hello/templates/index.html | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index 7e67973e7..db3ce2e39 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -1,4 +1,4 @@ -""" +F""" Django settings for gettingstarted project. Generated by 'django-admin startproject' using Django 6.0. @@ -44,7 +44,7 @@ # Debug mode will be automatically enabled when the project is run via `heroku local` (which # loads the environment variables set in the `.env` file, where `ENVIRONMENT=development`). # SECURITY WARNING: Don't run with debug turned on in production! -DEBUG = os.environ.get("ENVIRONMENT") == "development" +DEBUG = True # The `DYNO` env var is set on Heroku CI, but it's not a real Heroku app, so we have to # also explicitly exclude CI: @@ -56,7 +56,7 @@ # validation of the Host header in the incoming HTTP request. On other platforms you may need to # list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See: # https://docs.djangoproject.com/en/6.0/ref/settings/#std-setting-ALLOWED_HOSTS - ALLOWED_HOSTS = ["*"] + ALLOWED_HOSTS = ['python-getting-started-lab1-lk4l.onrender.com'] # Redirect all non-HTTPS requests to HTTPS. This requires that: # 1. Your app has a TLS/SSL certificate, which all `*.herokuapp.com` domains do by default. @@ -70,7 +70,7 @@ # https://docs.djangoproject.com/en/6.0/ref/middleware/#http-strict-transport-security SECURE_SSL_REDIRECT = True else: - ALLOWED_HOSTS = ["*"] + ALLOWED_HOSTS = ['python-getting-started-lab1-lk4l.onrender.com'] # Application definition @@ -208,7 +208,7 @@ WHITENOISE_KEEP_ONLY_HASHED_FILES = True # Customise the default logging config, since by default full Django logs are only emitted when -# `DEBUG=True` (which otherwise makes diagnosing errors much harder in production): +# DEBUG=True (which otherwise makes diagnosing errors much harder in production): # https://docs.djangoproject.com/en/6.0/ref/logging/#default-logging-configuration # For more advanced logging you may want to try: https://django-structlog.readthedocs.io LOGGING = { diff --git a/hello/templates/index.html b/hello/templates/index.html index b4f60e59b..fd1dc31c0 100644 --- a/hello/templates/index.html +++ b/hello/templates/index.html @@ -8,7 +8,7 @@ -

Getting Started with Python on Heroku

+

Getting Started with Python on Heroku z UKEN

This is a sample Python application deployed to Heroku. It's a reasonably simple app - but a good foundation for understanding how to get the most out of the Heroku platform.

Getting Started on Heroku with Python Getting Started on Heroku Fir with Python From 025a37c6cf1b3e131d860be6f45a874afd18bef9 Mon Sep 17 00:00:00 2001 From: Dezik Date: Thu, 18 Dec 2025 17:16:25 +0100 Subject: [PATCH 06/10] asdas --- gettingstarted/settings.py | 7 +++---- hello/migrations/0002_visit.py | 20 ++++++++++++++++++++ hello/models.py | 5 +++-- hello/templates/index.html | 2 ++ hello/views.py | 8 +++++++- requirements.txt | 17 ++++++++++------- 6 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 hello/migrations/0002_visit.py diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index db3ce2e39..b820871ce 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -56,7 +56,7 @@ # validation of the Host header in the incoming HTTP request. On other platforms you may need to # list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See: # https://docs.djangoproject.com/en/6.0/ref/settings/#std-setting-ALLOWED_HOSTS - ALLOWED_HOSTS = ['python-getting-started-lab1-lk4l.onrender.com'] + ALLOWED_HOSTS = ['python-getting-started-lab1-lk4l.onrender.com', '127.0.0.1'] # Redirect all non-HTTPS requests to HTTPS. This requires that: # 1. Your app has a TLS/SSL certificate, which all `*.herokuapp.com` domains do by default. @@ -70,7 +70,7 @@ # https://docs.djangoproject.com/en/6.0/ref/middleware/#http-strict-transport-security SECURE_SSL_REDIRECT = True else: - ALLOWED_HOSTS = ['python-getting-started-lab1-lk4l.onrender.com'] + ALLOWED_HOSTS = ['python-getting-started-lab1-lk4l.onrender.com','127.0.0.1'] # Application definition @@ -141,10 +141,9 @@ # https://github.com/jazzband/dj-database-url DATABASES = { "default": dj_database_url.config( - env="DATABASE_URL", + default=os.environ.get("DATABASE_URL", "sqlite:///db.sqlite3"), conn_max_age=600, conn_health_checks=True, - ssl_require=True, ), } else: diff --git a/hello/migrations/0002_visit.py b/hello/migrations/0002_visit.py new file mode 100644 index 000000000..1d85f64b8 --- /dev/null +++ b/hello/migrations/0002_visit.py @@ -0,0 +1,20 @@ +# Generated by Django 6.0 on 2025-12-18 16:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hello', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Visit', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/hello/models.py b/hello/models.py index 974d64f7e..417367851 100644 --- a/hello/models.py +++ b/hello/models.py @@ -1,7 +1,8 @@ from django.db import models -# Create your models here. - class Greeting(models.Model): when = models.DateTimeField("date created", auto_now_add=True) + +class Visit(models.Model): + created_at = models.DateTimeField(auto_now_add=True) \ No newline at end of file diff --git a/hello/templates/index.html b/hello/templates/index.html index fd1dc31c0..cdbd23940 100644 --- a/hello/templates/index.html +++ b/hello/templates/index.html @@ -9,6 +9,7 @@

Getting Started with Python on Heroku z UKEN

+

Liczba odwiedzin tej strony zapisanych w bazie: {{ visits }}

This is a sample Python application deployed to Heroku. It's a reasonably simple app - but a good foundation for understanding how to get the most out of the Heroku platform.

Getting Started on Heroku with Python Getting Started on Heroku Fir with Python @@ -28,6 +29,7 @@

Getting Started with Python on Heroku z UKEN

How this sample app works

    +
  • This app was deployed to Heroku using Git.
  • When Heroku received the source code, it fetched all the dependencies in requirements.txt, creating a deployable build artifact.
  • The platform then spins up a dyno, a lightweight container that provides an isolated environment in which the build artifact can be mounted and executed.
  • diff --git a/hello/views.py b/hello/views.py index bd7a34b00..b232f85a6 100644 --- a/hello/views.py +++ b/hello/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render - +from .models import Greeting, Visit from .models import Greeting # Create your views here. @@ -26,3 +26,9 @@ def db(request): greetings = Greeting.objects.all() return render(request, "db.html", {"greetings": greetings}) + +def index(request): + # Zapis każdej wizyty w bazie + Visit.objects.create() #<-dodanie linii + visits = Visit.objects.count() #<-dodanie linii + return render(request, "index.html", {"visits": visits}) #<-dodanie {.....}W \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7194eee9a..370df7fbf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,10 @@ -django>=6.0,<6.1 -gunicorn>=23,<24 -dj-database-url>=3,<4 -whitenoise>=6,<7 - -# Uncomment to use a Postgres database. -#psycopg[binary] +asgiref==3.11.0 +dj-database-url==3.0.1 +Django==6.0 +gunicorn==23.0.0 +packaging==25.0 +psycopg==3.3.2 +psycopg-binary==3.3.2 +sqlparse==0.5.4 +tzdata==2025.3 +whitenoise==6.11.0 From eccd0f0543786c12cd49300624f5258ad9a3defe Mon Sep 17 00:00:00 2001 From: Dezik Date: Fri, 19 Dec 2025 00:41:50 +0100 Subject: [PATCH 07/10] fix for sqllite --- gettingstarted/settings.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index b820871ce..bd98f2179 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -133,29 +133,12 @@ # Database # https://docs.djangoproject.com/en/6.0/ref/settings/#databases -if IS_HEROKU_APP: - # In production on Heroku the database configuration is derived from the `DATABASE_URL` - # environment variable by the dj-database-url package. `DATABASE_URL` will be set - # automatically by Heroku when a database addon is attached to your Heroku app. See: - # https://devcenter.heroku.com/articles/provisioning-heroku-postgres#application-config-vars - # https://github.com/jazzband/dj-database-url - DATABASES = { - "default": dj_database_url.config( - default=os.environ.get("DATABASE_URL", "sqlite:///db.sqlite3"), - conn_max_age=600, - conn_health_checks=True, - ), - } -else: - # When running locally in development or in CI, a sqlite database file will be used instead - # to simplify initial setup. Longer term it's recommended to use Postgres locally too. - DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", - } +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", } - +} # Password validation # https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators From e658accc81e10ba1e4e846946190f3a432c3f8fb Mon Sep 17 00:00:00 2001 From: Dezik Date: Fri, 19 Dec 2025 00:46:56 +0100 Subject: [PATCH 08/10] Switch to PostgreSQL and add auto-migrations --- gettingstarted/settings.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index bd98f2179..c8e0d75ce 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -133,12 +133,29 @@ # Database # https://docs.djangoproject.com/en/6.0/ref/settings/#databases -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", +if IS_HEROKU_APP: + # In production on Heroku the database configuration is derived from the `DATABASE_URL` + # environment variable by the dj-database-url package. `DATABASE_URL` will be set + # automatically by Heroku when a database addon is attached to your Heroku app. See: + # https://devcenter.heroku.com/articles/provisioning-heroku-postgres#application-config-vars + # https://github.com/jazzband/dj-database-url + DATABASES = { + "default": dj_database_url.config( + default=os.environ.get("DATABASE_URL", "sqlite:///db.sqlite3"), + conn_max_age=600, + conn_health_checks=True, + ), } -} +# else: + # When running locally in development or in CI, a sqlite database file will be used instead + # to simplify initial setup. Longer term it's recommended to use Postgres locally too. + # DATABASES = { + # "default": { + # "ENGINE": "django.db.backends.sqlite3", + # "NAME": BASE_DIR / "db.sqlite3", + # } + # } + # Password validation # https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators From f7af23f457b76c365c20540bcbdfef4935f61966 Mon Sep 17 00:00:00 2001 From: Dezik Date: Fri, 19 Dec 2025 00:49:41 +0100 Subject: [PATCH 09/10] Switch to PostgreSQL and add auto-migrations --- gettingstarted/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index c8e0d75ce..fdbb9636c 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -133,7 +133,7 @@ # Database # https://docs.djangoproject.com/en/6.0/ref/settings/#databases -if IS_HEROKU_APP: +#if IS_HEROKU_APP: # In production on Heroku the database configuration is derived from the `DATABASE_URL` # environment variable by the dj-database-url package. `DATABASE_URL` will be set # automatically by Heroku when a database addon is attached to your Heroku app. See: From c40f253f594ed04e4cce42a7f8f01e3ad972d5a0 Mon Sep 17 00:00:00 2001 From: Dezik Date: Fri, 19 Dec 2025 00:59:48 +0100 Subject: [PATCH 10/10] Switch to PostgreSQL and add auto-migrations --- gettingstarted/settings.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index fdbb9636c..b820871ce 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -133,7 +133,7 @@ # Database # https://docs.djangoproject.com/en/6.0/ref/settings/#databases -#if IS_HEROKU_APP: +if IS_HEROKU_APP: # In production on Heroku the database configuration is derived from the `DATABASE_URL` # environment variable by the dj-database-url package. `DATABASE_URL` will be set # automatically by Heroku when a database addon is attached to your Heroku app. See: @@ -146,15 +146,15 @@ conn_health_checks=True, ), } -# else: +else: # When running locally in development or in CI, a sqlite database file will be used instead # to simplify initial setup. Longer term it's recommended to use Postgres locally too. - # DATABASES = { - # "default": { - # "ENGINE": "django.db.backends.sqlite3", - # "NAME": BASE_DIR / "db.sqlite3", - # } - # } + DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } + } # Password validation