Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions gettingstarted/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
F"""
Django settings for gettingstarted project.

Generated by 'django-admin startproject' using Django 6.0.
Expand Down Expand Up @@ -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:
Expand All @@ -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', '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.
Expand All @@ -70,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 = ['python-getting-started-lab1-lk4l.onrender.com','127.0.0.1']


# Application definition
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -208,7 +207,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 = {
Expand Down
20 changes: 20 additions & 0 deletions hello/migrations/0002_visit.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
5 changes: 3 additions & 2 deletions hello/models.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion hello/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<a href="/" class="lang-logo">
<img src="{% static 'lang-logo.png'%}">
</a>
<h1>Getting Started with Python on Heroku</h1>
<h1>Getting Started with Python on Heroku z UKEN</h1>
<p>Liczba odwiedzin tej strony zapisanych w bazie: {{ visits }}</p>
<p>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.</p>
<a type="button" class="btn btn-lg btn-default" href="https://devcenter.heroku.com/articles/getting-started-with-python"><span class="glyphicon glyphicon-flash"></span> Getting Started on Heroku with Python</a>
<a type="button" class="btn btn-lg btn-default" href="https://devcenter.heroku.com/articles/getting-started-with-python-fir"><span class="glyphicon glyphicon-flash"></span> Getting Started on Heroku Fir with Python</a>
Expand All @@ -28,6 +29,7 @@ <h1>Getting Started with Python on Heroku</h1>
<div class="col-md-6">
<h3><span class="glyphicon glyphicon-info-sign"></span> How this sample app works</h3>
<ul>

<li>This app was deployed to Heroku using Git.</li>
<li>When Heroku received the source code, it fetched all the dependencies in <a href="https://github.com/heroku/python-getting-started/blob/main/requirements.txt">requirements.txt</a>, creating a deployable build artifact.</li>
<li>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.</li>
Expand Down
8 changes: 7 additions & 1 deletion hello/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render

from .models import Greeting, Visit
from .models import Greeting

# Create your views here.
Expand All @@ -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
17 changes: 10 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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