Commit 7284e776 by Patryk Czarnik

Django - datetime bez szablonu

parent bc7c778b
from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from datetime import datetime
# Create your views here.
def hello(request):
return HttpResponse('Hello <strong style="color:red">Django</strong>!')
def czas_txt(request):
return HttpResponse(str(datetime.now()))
def czas_html(request:HttpRequest) -> HttpResponse:
godzina = datetime.now().strftime('%H:%M:%S')
html = f'''<!DOCTYPE html>
<html><head>
<title>Która godzina</title>
</head>
<body style="background-color: #FFFFDD">
<p>Teraz jest godzina <strong style="color:purple">{godzina}</strong></p>
</body>
</html>
'''
return HttpResponse(html)
......@@ -16,9 +16,11 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from aplikacja.views import hello
from aplikacja.views import *
urlpatterns = [
path("admin/", admin.site.urls),
path("hello", hello),
path("czas.txt", czas_txt),
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