From 34c8bae8994626290ba386d68f1cf771c150388b Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Mon, 24 Jun 2024 22:13:32 +0100 Subject: [PATCH] Make a start on the templates --- config/settings/base.py | 4 ++-- config/urls.py | 4 +++- reinheit/apps/brew/urls.py | 7 +++++++ reinheit/apps/brew/views.py | 13 ++++++++++++- reinheit/templates/base.html | 2 ++ reinheit/templates/brew/brew_list.html | 8 ++++++++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 reinheit/apps/brew/urls.py create mode 100644 reinheit/templates/base.html create mode 100644 reinheit/templates/brew/brew_list.html diff --git a/config/settings/base.py b/config/settings/base.py index 47631c6..8086e41 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -13,7 +13,7 @@ https://docs.djangoproject.com/en/5.0/ref/settings/ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = Path(__file__).resolve().parent.parent.parent # Quick-start development settings - unsuitable for production @@ -58,7 +58,7 @@ ROOT_URLCONF = "config.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], + "DIRS": [BASE_DIR/"reinheit"/"templates"], "APP_DIRS": True, "OPTIONS": { "context_processors": [ diff --git a/config/urls.py b/config/urls.py index d469a3e..b830bd4 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,6 +1,8 @@ -from django.urls import path +from django.urls import path, include from django.contrib import admin urlpatterns = [ path("admin/", admin.site.urls), + + path("brews/", include(("reinheit.apps.brew.urls", "brew"), namespace="brews")) ] diff --git a/reinheit/apps/brew/urls.py b/reinheit/apps/brew/urls.py new file mode 100644 index 0000000..b6936ab --- /dev/null +++ b/reinheit/apps/brew/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from .views import BrewListView + +urlpatterns = [ + path("brews/", BrewListView.as_view(), name="list") +] diff --git a/reinheit/apps/brew/views.py b/reinheit/apps/brew/views.py index 91ea44a..09ec38c 100644 --- a/reinheit/apps/brew/views.py +++ b/reinheit/apps/brew/views.py @@ -1,3 +1,14 @@ -from django.shortcuts import render +from django.views.generic import ListView + +from .models import Brew # Create your views here. + + +class BrewListView(ListView): + model = Brew + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + print(context) + return context diff --git a/reinheit/templates/base.html b/reinheit/templates/base.html new file mode 100644 index 0000000..90531a4 --- /dev/null +++ b/reinheit/templates/base.html @@ -0,0 +1,2 @@ + + diff --git a/reinheit/templates/brew/brew_list.html b/reinheit/templates/brew/brew_list.html new file mode 100644 index 0000000..79152df --- /dev/null +++ b/reinheit/templates/brew/brew_list.html @@ -0,0 +1,8 @@ +{% include "base.html" %} + +{% block content %} + {% for brew in brew_list %} + {{ brew }} + {% endfor %} + +{% endblock content %}