Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Solution' #861

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added static/css/styles.css
Empty file.
9 changes: 9 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
from taxi.views import index


urlpatterns = [
path("", index, name="index")
]

app_name = "taxi"
16 changes: 15 additions & 1 deletion taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
from django.shortcuts import render

from django.http import HttpResponse, HttpRequest
from .models import Manufacturer, Driver, 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)
7 changes: 5 additions & 2 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"-#&ricv159p0pypoh5_lgm*)-dfcjqe=yc"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False

ALLOWED_HOSTS = []
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -56,7 +56,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -124,6 +124,9 @@

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

Expand Down
8 changes: 6 additions & 2 deletions taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
path("admin/", admin.site.urls),
]
path("taxi/", include("taxi.urls", namespace="taxi"))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
16 changes: 16 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Taxi Service</title>
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}
{% block content %}
{% endblock %}
</body>
</html>
6 changes: 6 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ul>
<li><a href="#">Home page</a></li>
<li><a href="#">Manufacturers</a></li>
<li><a href="#">Cars</a></li>
<li><a href="#">Drivers</a></li>
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
</ul>
9 changes: 9 additions & 0 deletions templates/taxi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}

{% block content %}
<ul>
<li>Num of cars: {{ num_cars }}</li>
<li>Num of drivers: {{ num_drivers }}</li>
<li>Num of manufacturers: {{ num_manufacturers }}</li>
</ul>
{% endblock %}
Loading