From a2f9d142106fd202f66acbd8848545654f05f905 Mon Sep 17 00:00:00 2001 From: Bohdan Bastiuk Date: Sat, 16 Nov 2024 18:17:30 +0100 Subject: [PATCH 1/2] Solution --- .gitignore | 6 +++--- static/__init__.py | 0 static/css/__init__.py | 0 static/css/styles.css | 6 ++++++ taxi/urls.py | 10 ++++++++++ taxi/views.py | 13 ++++++++++++- taxi_service/settings.py | 3 ++- taxi_service/urls.py | 8 +++++--- templates/__init__.py | 0 templates/base.html | 25 +++++++++++++++++++++++++ templates/includes/__init__.py | 0 templates/includes/sidebar.html | 6 ++++++ templates/taxi/__init__.py | 0 templates/taxi/index.html | 18 ++++++++++++++++++ 14 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 static/__init__.py create mode 100644 static/css/__init__.py create mode 100644 static/css/styles.css create mode 100644 taxi/urls.py create mode 100644 templates/__init__.py create mode 100644 templates/base.html create mode 100644 templates/includes/__init__.py create mode 100644 templates/includes/sidebar.html create mode 100644 templates/taxi/__init__.py create mode 100644 templates/taxi/index.html diff --git a/.gitignore b/.gitignore index 17d458190..c0851f69b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ .idea/ .vscode/ -*.iml +.iml .env .DS_Store -venv/ +.venv/ .pytest_cache/ -**__pycache__/ +__pycache__/ *.pyc app/db.sqlite3 db.sqlite3 diff --git a/static/__init__.py b/static/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/static/css/__init__.py b/static/css/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/static/css/styles.css b/static/css/styles.css new file mode 100644 index 000000000..26e33776b --- /dev/null +++ b/static/css/styles.css @@ -0,0 +1,6 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + margin: 0; + padding: 0; +} \ No newline at end of file diff --git a/taxi/urls.py b/taxi/urls.py new file mode 100644 index 000000000..bd33074c8 --- /dev/null +++ b/taxi/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from django.conf import settings +from django.conf.urls.static import static +from . import views + +app_name = "taxi" + +urlpatterns = [ + path("", views.index, name="index"), +] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/taxi/views.py b/taxi/views.py index 91ea44a21..424a93f92 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -1,3 +1,14 @@ from django.shortcuts import render +from .models import Driver, Manufacturer, Car -# Create your views here. +def index(request): + 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) \ No newline at end of file diff --git a/taxi_service/settings.py b/taxi_service/settings.py index 00329f55f..42a0a736c 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": [ @@ -123,6 +123,7 @@ # https://docs.djangoproject.com/en/4.0/howto/static-files/ 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..491212e7c 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 +from taxi import views urlpatterns = [ - path("admin/", admin.site.urls), + path("", views.index, name="home"), + path("taxi/", include("taxi.urls", namespace="taxi")), ] + diff --git a/templates/__init__.py b/templates/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 000000000..b76995315 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,25 @@ + + + + {% block title %} + Example Title + {% endblock %} + + + + + {% load static %} + + + + + +
+ {% block content %}{% endblock %} +
+ + diff --git a/templates/includes/__init__.py b/templates/includes/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/templates/includes/sidebar.html b/templates/includes/sidebar.html new file mode 100644 index 000000000..ea54ade03 --- /dev/null +++ b/templates/includes/sidebar.html @@ -0,0 +1,6 @@ + diff --git a/templates/taxi/__init__.py b/templates/taxi/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/templates/taxi/index.html b/templates/taxi/index.html new file mode 100644 index 000000000..156ac384c --- /dev/null +++ b/templates/taxi/index.html @@ -0,0 +1,18 @@ + + + + + Home page + + + {% block content %} +

Home page

+

Statistics

+ + {% endblock %} + + From f5f58bd72aa240ed8dcdcf89ab8fbd8bde6c4c10 Mon Sep 17 00:00:00 2001 From: Bohdan Bastiuk Date: Sat, 16 Nov 2024 18:22:44 +0100 Subject: [PATCH 2/2] Solution fix flake --- taxi/views.py | 11 ++++++----- taxi_service/urls.py | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/taxi/views.py b/taxi/views.py index 424a93f92..7552f867b 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -1,14 +1,15 @@ from django.shortcuts import render from .models import Driver, Manufacturer, Car + def index(request): 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) \ No newline at end of file + "num_drivers": num_drivers, + "num_manufacturers": num_manufacturers, + "num_cars": num_cars, + } + return render(request, "taxi/index.html", context) diff --git a/taxi_service/urls.py b/taxi_service/urls.py index 491212e7c..097c9f9a7 100644 --- a/taxi_service/urls.py +++ b/taxi_service/urls.py @@ -20,4 +20,3 @@ path("", views.index, name="home"), path("taxi/", include("taxi.urls", namespace="taxi")), ] -