From 4e05dc15a58bc8d3cb6ca7986651791a5aef76e4 Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Sat, 6 Apr 2024 10:08:29 +0200 Subject: [PATCH] Home --- project/jinja2env.py | 8 ++++ project/main/templates/main/base/base.html | 14 +++++++ .../templates/main/base/body_content.html | 7 ++++ project/main/templates/main/home.html | 34 +++++++++++++++ project/main/views.py | 3 -- project/main/views/__init__.py | 1 + project/main/views/home.py | 5 +++ project/settings.py | 41 +++++++++++++++---- project/urls.py | 21 ++-------- 9 files changed, 105 insertions(+), 29 deletions(-) create mode 100644 project/jinja2env.py create mode 100644 project/main/templates/main/base/base.html create mode 100644 project/main/templates/main/base/body_content.html create mode 100644 project/main/templates/main/home.html delete mode 100644 project/main/views.py create mode 100644 project/main/views/__init__.py create mode 100644 project/main/views/home.py diff --git a/project/jinja2env.py b/project/jinja2env.py new file mode 100644 index 0000000..eadb3a6 --- /dev/null +++ b/project/jinja2env.py @@ -0,0 +1,8 @@ +from jinja2 import Environment + + +def environment(**options): + env = Environment(**options) + + env.globals.update({}) + return env diff --git a/project/main/templates/main/base/base.html b/project/main/templates/main/base/base.html new file mode 100644 index 0000000..468f2e2 --- /dev/null +++ b/project/main/templates/main/base/base.html @@ -0,0 +1,14 @@ + + + + + + + + Django-html demo + + + {% block body_content %}{% endblock %} + + \ No newline at end of file diff --git a/project/main/templates/main/base/body_content.html b/project/main/templates/main/base/body_content.html new file mode 100644 index 0000000..854b3ed --- /dev/null +++ b/project/main/templates/main/base/body_content.html @@ -0,0 +1,7 @@ +{% extends "main/base/base.html" %} + +{% block body_content %} +
+ {% block content %}{% endblock %} +
+{% endblock %} diff --git a/project/main/templates/main/home.html b/project/main/templates/main/home.html new file mode 100644 index 0000000..b46c9b5 --- /dev/null +++ b/project/main/templates/main/home.html @@ -0,0 +1,34 @@ +{% extends "main/base/base.html" %} + + +{% macro list_item(content, url) %} +
  • + + {{ content }} + +
  • +{% endmacro %} + + +{% block body_content %} +
    +
    +

    + Django + htmx +

    + +

    Useful Links

    +
      + {{ list_item("Django", "https://www.djangoproject.com") }} + {{ list_item("htmx", "https://htmx.org") }} + {{ list_item("Django + htmx repository", "https://gitea.ekirin.com/Intis/django-htmx-presenatation") }} +
    + +

    + + Start demo + +

    +
    +
    +{% endblock %} diff --git a/project/main/views.py b/project/main/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/project/main/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/project/main/views/__init__.py b/project/main/views/__init__.py new file mode 100644 index 0000000..aa2cb2e --- /dev/null +++ b/project/main/views/__init__.py @@ -0,0 +1 @@ +from .home import HomeView diff --git a/project/main/views/home.py b/project/main/views/home.py new file mode 100644 index 0000000..425290a --- /dev/null +++ b/project/main/views/home.py @@ -0,0 +1,5 @@ +from django.views.generic import TemplateView + + +class HomeView(TemplateView): + template_name = "main/home.html" diff --git a/project/settings.py b/project/settings.py index 2d455c9..12df2da 100644 --- a/project/settings.py +++ b/project/settings.py @@ -14,6 +14,7 @@ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +PROJECT_PATH = BASE_DIR / "project" # Quick-start development settings - unsuitable for production @@ -31,7 +32,6 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ - "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", @@ -53,16 +53,41 @@ ROOT_URLCONF = "project.urls" TEMPLATES = [ { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], + "BACKEND": "django.template.backends.jinja2.Jinja2", + "DIRS": [ + PROJECT_PATH.joinpath("main/templates"), + PROJECT_PATH.joinpath("user_area/templates"), + ], "APP_DIRS": True, "OPTIONS": { - "context_processors": [ - "django.template.context_processors.debug", - "django.template.context_processors.request", - "django.contrib.auth.context_processors.auth", - "django.contrib.messages.context_processors.messages", + # 'match_extension': '.jinja', + # 'match_regex': '*\.jinja$', # This is exclusive with 'match_extension' + # 'newstyle_gettext': True, + # 'filters': { + # 'jinja_filters': 'project.main.jinja_filters', + # }, + # 'globals': { + # 'jinja_globals': 'project.main.jinja_globals', + # }, + "environment": "project.jinja2env.environment", + "extensions": [ + "jinja2.ext.do", + "jinja2.ext.loopcontrols", + # "jinja2.ext.with_", + "jinja2.ext.i18n", + # "jinja2.ext.autoescape", + "django_jinja.builtins.extensions.CsrfExtension", + "django_jinja.builtins.extensions.CacheExtension", + "django_jinja.builtins.extensions.TimezoneExtension", + "django_jinja.builtins.extensions.UrlsExtension", + "django_jinja.builtins.extensions.StaticFilesExtension", + "django_jinja.builtins.extensions.DjangoFiltersExtension", ], + "autoescape": True, + "trim_blocks": True, + "lstrip_blocks": True, + "auto_reload": DEBUG, + # 'translation_engine': 'django.utils.translation', }, }, ] diff --git a/project/urls.py b/project/urls.py index 6e17094..ec3b0b8 100644 --- a/project/urls.py +++ b/project/urls.py @@ -1,22 +1,7 @@ -""" -URL configuration for project project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.0/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 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 project.main import views + urlpatterns = [ - path("admin/", admin.site.urls), + path("", views.HomeView.as_view(), name="home"), ]