Commit da6990b1 by Patryk Czarnik

Dodanie szablonu i wodoków dla aplikacji sklep

parent 13221ab0
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>Produkty naszego sklepu</title>
</head>
<body>
<h1>Lista towarów</h1>
<ul>
{% for p in products %}
<li>towar: {{ p.name }} - cena {{ p.price }} zł, {{ p.vat_jako_calkowita }}% VAT
{% if p.valid_to %}
<br/>(termin ważności {{p.valid_to}})
{% endif %}
{% if not p.available %}
<br/><strong>Produkt niedostępny</strong>
{% endif %}
</li>
{% endfor %}
</ul>
</body>
</html>
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from .models import *
# Create your views here.
def lista_produktow(request: HttpRequest) -> HttpResponse:
produkty = Product.objects.all()
return HttpResponse(str(produkty), content_type='text/plain')
def lista_produktow_txt(request: HttpRequest) -> HttpResponse:
products = Product.objects.all()
wynik = 'Produkty naszego sklepu:'
for product in products:
wynik += f'\n - {product.name} za {product.price} zł'
if product.valid_to is not None:
wynik += f', termin ważności: {product.valid_to}'
return HttpResponse(wynik, content_type='text/plain;charset=utf-8')
def lista_produktow_html(request: HttpRequest) -> HttpResponse:
products = Product.objects.all()
return render(request, 'towary.html', context={'products': products})
......@@ -17,7 +17,10 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
# dwa style importowania do wyboru:
from aplikacja.views import *
import sklep.views
urlpatterns = [
path("admin/", admin.site.urls),
......@@ -30,4 +33,7 @@ urlpatterns = [
path("kalkulator", kalkulator),
path("kalkulator_post", kalkulator_post),
path("formularz", formularz),
path("sklep", sklep.views.lista_produktow),
path("sklep.txt", sklep.views.lista_produktow_txt),
path("sklep.html", sklep.views.lista_produktow_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