From 9c78e6c97149c9ec25cfff06ae996e7198571eed Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 18 Nov 2024 00:10:00 +0200 Subject: [PATCH] Solution --- static/css/styles.css | 9 +++++++++ taxi/urls.py | 9 +++++++++ taxi/views.py | 15 ++++++++++++++- taxi_service/settings.py | 6 +++++- taxi_service/urls.py | 6 +++++- templates/base.html | 29 +++++++++++++++++++++++++++++ templates/includes/sidebar.html | 14 ++++++++++++++ templates/taxi/index.html | 12 ++++++++++++ 8 files changed, 97 insertions(+), 3 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..25c5533af --- /dev/null +++ b/static/css/styles.css @@ -0,0 +1,9 @@ +body { + margin-top: 20px; + background: cadetblue; +} + +.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..3d7afb085 --- /dev/null +++ b/taxi/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from taxi.views import index + + +app_name = "taxi" +urlpatterns = [ + path("", index, name="index"), +] diff --git a/taxi/views.py b/taxi/views.py index 91ea44a21..725860f8c 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -1,3 +1,16 @@ +from django.http import HttpRequest, HttpResponse from django.shortcuts import render +from .models import Driver, Manufacturer, Car -# Create your views here. + +def index(request: HttpRequest) -> HttpResponse: + num_drivers = Driver.objects.count() + num_manufacturers = Manufacturer.objects.count() + num_cars = Car.objects.count() + context = { + "num_drivers": num_drivers, + "num_manufacturers": num_manufacturers, + "num_cars": num_cars, + } + + return render(request, "taxi/index.html", context=context) diff --git a/taxi_service/settings.py b/taxi_service/settings.py index 00329f55f..d349ecb2b 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": [ @@ -122,6 +122,10 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ +STATICFILES_DIRS = [ + BASE_DIR / "static", +] + STATIC_URL = "static/" # Default primary key field type diff --git a/taxi_service/urls.py b/taxi_service/urls.py index 57c939e7f..ebb1c52b3 100644 --- a/taxi_service/urls.py +++ b/taxi_service/urls.py @@ -14,8 +14,12 @@ 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 + +import taxi + 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..8070f878c --- /dev/null +++ b/templates/base.html @@ -0,0 +1,29 @@ + + + + {% block title %} + Taxi Service + {% endblock %} + + + + {% 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..2fab35ed2 --- /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..14b64e27f --- /dev/null +++ b/templates/taxi/index.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block content %} +

Taxi HomePage

+

Welcome To Our Teleport-Taxi

+

Our Service is:

+ +{% endblock %}