Commit 59bc72b1 by Patryk Czarnik

odczyt czasu - wersja html

parent e7b03705
...@@ -8,10 +8,20 @@ from datetime import datetime ...@@ -8,10 +8,20 @@ from datetime import datetime
def hello(request): def hello(request):
return HttpResponse('Hello world') return HttpResponse('Hello world')
# Dopisz funkcję, która zwraca bieżący czas
def podaj_czas(request): def podaj_czas(request):
dt = datetime.now() dt = datetime.now()
return HttpResponse(dt) return HttpResponse(dt, content_type='text/plain;charset=UTF-8')
# uwzględnij tę funkcję w urls # prosty sposób, aby zwrócić treść w formacie HTML
# i przetestuj w przeglądarce # po prostu tworzymy HTML w funkcji Pythona i wstawiamy do HttpResponse
def czas_html(request):
godzina = datetime.now().strftime('%H:%M:%S')
html = f'''<html><head>
<title>Która godzina</title>
</head>
<body style="background-color: #FFFFDD">
<p>Teraz jest późna godzina <strong style="color:purple">{godzina}</strong></p>
</body>
</html>
'''
return HttpResponse(html, content_type='text/html;charset=UTF-8')
...@@ -18,11 +18,11 @@ Including another URLconf ...@@ -18,11 +18,11 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from aplikacja.views import hello from aplikacja.views import *
from aplikacja.views import podaj_czas
urlpatterns = [ urlpatterns = [
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("hello", hello), path("hello", hello),
path("czas", podaj_czas), path("czas", podaj_czas),
path("czas_html", czas_html),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment