Home
This commit is contained in:
8
project/jinja2env.py
Normal file
8
project/jinja2env.py
Normal file
@ -0,0 +1,8 @@
|
||||
from jinja2 import Environment
|
||||
|
||||
|
||||
def environment(**options):
|
||||
env = Environment(**options)
|
||||
|
||||
env.globals.update({})
|
||||
return env
|
||||
14
project/main/templates/main/base/base.html
Normal file
14
project/main/templates/main/base/base.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=100%, user-scalable=yes, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://unpkg.com/htmx.org@1.9.11" integrity="sha384-0gxUXCCR8yv9FM2b+U3FDbsKthCI66oH5IA9fHppQq9DDMHuMauqq1ZHBpJxQ0J0" crossorigin="anonymous"></script>
|
||||
<title>Django-html demo</title>
|
||||
</head>
|
||||
<body>
|
||||
{% block body_content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
7
project/main/templates/main/base/body_content.html
Normal file
7
project/main/templates/main/base/body_content.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends "main/base/base.html" %}
|
||||
|
||||
{% block body_content %}
|
||||
<div class="container">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
34
project/main/templates/main/home.html
Normal file
34
project/main/templates/main/home.html
Normal file
@ -0,0 +1,34 @@
|
||||
{% extends "main/base/base.html" %}
|
||||
|
||||
|
||||
{% macro list_item(content, url) %}
|
||||
<li>
|
||||
<a href="{{ url }}" target="_blank">
|
||||
{{ content }}
|
||||
</a>
|
||||
</li>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% block body_content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-6">
|
||||
<h1 class="mt-5 mb-5 pb-3 border-bottom border-dark">
|
||||
Django + htmx
|
||||
</h1>
|
||||
|
||||
<h4>Useful Links</h4>
|
||||
<ul>
|
||||
{{ 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") }}
|
||||
</ul>
|
||||
|
||||
<h4 class="mt-5">
|
||||
<a href="#">
|
||||
Start demo
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -1,3 +0,0 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
1
project/main/views/__init__.py
Normal file
1
project/main/views/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .home import HomeView
|
||||
5
project/main/views/home.py
Normal file
5
project/main/views/home.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
|
||||
class HomeView(TemplateView):
|
||||
template_name = "main/home.html"
|
||||
@ -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',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
@ -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"),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user