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 #876

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.idea/
.vscode/
*.iml
.iml
Shayba228 marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an extra space before .iml. Consider removing it for consistency.

.env
.DS_Store
venv/
.venv/
.pytest_cache/
**__pycache__/
__pycache__/
*.pyc
app/db.sqlite3
db.sqlite3
Shayba228 marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines 10 to 11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entry db.sqlite3 is duplicated. Please remove one of these entries to avoid redundancy.

Empty file added static/__init__.py
Empty file.
Empty file added static/css/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}
10 changes: 10 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
Shayba228 marked this conversation as resolved.
Show resolved Hide resolved
from . import views

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import of views is unnecessary if you are not using it in this file. Consider removing it to clean up the code.


app_name = "taxi"

urlpatterns = [
path("", views.index, name="index"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Shayba228 marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 13 additions & 1 deletion taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
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)
3 changes: 2 additions & 1 deletion taxi_service/settings.py
Original file line number Diff line number Diff line change
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 @@ -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
Expand Down
7 changes: 4 additions & 3 deletions taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
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
Shayba228 marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import of views is unnecessary if you are not using it in this file. Consider removing it to clean up the code.


urlpatterns = [
path("admin/", admin.site.urls),
path("", views.index, name="home"),
path("taxi/", include("taxi.urls", namespace="taxi")),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace argument in the include function is incorrect. The correct usage is include('taxi.urls') without the namespace argument. Please remove it.

]
Empty file added templates/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% block title %}
<title>Example Title</title>
{% endblock %}

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">

</head>
<body>
<div id="sidebar">
{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
Empty file added templates/includes/__init__.py
Empty file.
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>
</ul>
Empty file added templates/taxi/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions templates/taxi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
Shayba228 marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index.html template should extend base.html to maintain a consistent layout. Add {% extends 'base.html' %} at the beginning of the file.

<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home page</title>
</head>
<body>
{% block content %}
<h1>Home page</h1>
<h2>Statistics</h2>
<ul>
<li>Number of cars: {{ num_cars }}</li>
<li>Number of drivers: {{ num_drivers }}</li>
<li>Number of manufacturers: {{ num_manufacturers }}</li>
</ul>
{% endblock %}
</body>
</html>
Loading