From e8bd81f9dba3caa87cdeb76556bac072d01eb4c7 Mon Sep 17 00:00:00 2001 From: Andrey Dementyev Date: Sun, 17 Nov 2024 17:14:18 +0200 Subject: [PATCH] 'Solution' --- static/css/styles.css | 8 ++++++++ taxi/urls.py | 9 +++++++++ taxi/views.py | 13 ++++++++++++- taxi_service/settings.py | 8 ++++++-- taxi_service/urls.py | 4 +++- templates/base.html | 27 +++++++++++++++++++++++++++ templates/includes/sidebar.html | 14 ++++++++++++++ templates/taxi/index.html | 10 ++++++++++ 8 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 static/css/styles.css create mode 100644 taxi/urls.py create mode 100644 templates/base.html create mode 100644 templates/includes/sidebar.html create mode 100644 templates/taxi/index.html diff --git a/static/css/styles.css b/static/css/styles.css new file mode 100644 index 000000000..09ad5c21d --- /dev/null +++ b/static/css/styles.css @@ -0,0 +1,8 @@ +body { + margin-top: 20px; +} + +.sidebar-nav { + padding: 0; + list-style: none; +} \ No newline at end of file diff --git a/taxi/urls.py b/taxi/urls.py new file mode 100644 index 000000000..b70860f68 --- /dev/null +++ b/taxi/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from taxi.views import index + +urlpatterns = [ + path("", index, name="index"), +] + +app_name = "taxi" diff --git a/taxi/views.py b/taxi/views.py index 91ea44a21..c64d90319 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -1,3 +1,14 @@ +from django.http import HttpRequest, HttpResponse from django.shortcuts import render +from .models import Car, Driver, Manufacturer -# Create your views here. +def index(request: HttpRequest) -> HttpResponse: + num_cars = Car.objects.count() + num_drivers = Driver.objects.count() + num_manufacturers = Manufacturer.objects.count() + context = { + "num_cars": num_cars, + "num_drivers": num_drivers, + "num_manufacturers": num_manufacturers, + } + return render(request, "taxi/index.html", context=context) diff --git a/taxi_service/settings.py b/taxi_service/settings.py index 00329f55f..36583edea 100644 --- a/taxi_service/settings.py +++ b/taxi_service/settings.py @@ -56,7 +56,7 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], + "DIRS": [BASE_DIR / 'templates'], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -112,7 +112,7 @@ LANGUAGE_CODE = "en-us" -TIME_ZONE = "UTC" +TIME_ZONE = "Europe/Kiev" USE_I18N = True @@ -124,6 +124,10 @@ STATIC_URL = "static/" +STATICFILES_DIRS = [ + BASE_DIR / "static", +] + # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field diff --git a/taxi_service/urls.py b/taxi_service/urls.py index 57c939e7f..d9133cde3 100644 --- a/taxi_service/urls.py +++ b/taxi_service/urls.py @@ -13,9 +13,11 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path("admin/", admin.site.urls), + path("", include("taxi.urls", namespace="taxi")) ] diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 000000000..95f0475ef --- /dev/null +++ b/templates/base.html @@ -0,0 +1,27 @@ + + + + Taxi Service + + + + {% load static %} + + + +
+
+
+ {% block sidebar %} + {% include "includes/sidebar.html" %} + {% endblock %} +
+
+ {% block content %} + {% endblock %} +
+
+
+ + diff --git a/templates/includes/sidebar.html b/templates/includes/sidebar.html new file mode 100644 index 000000000..00ee7dcde --- /dev/null +++ b/templates/includes/sidebar.html @@ -0,0 +1,14 @@ + diff --git a/templates/taxi/index.html b/templates/taxi/index.html new file mode 100644 index 000000000..150185b62 --- /dev/null +++ b/templates/taxi/index.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} +

Taxi service content:

+ +{% endblock %}