Skip to content

Commit 8dc173a

Browse files
committed
updates
1 parent af9acc0 commit 8dc173a

File tree

8 files changed

+126
-61
lines changed

8 files changed

+126
-61
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.PHONY dev:
2-
litestar run --reload --reload-dir=.
2+
dev:
3+
litestar run --reload --reload-dir=. --pdb
4+
5+

app.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
from litestar.contrib.htmx.request import HTMXRequest
1010
from litestar.contrib.jinja import JinjaTemplateEngine
1111
from litestar.enums import MediaType
12+
from litestar.logging import StructLoggingConfig
13+
from litestar.openapi import OpenAPIConfig
1214
from litestar.response import Response, Template
1315
from litestar.template.config import TemplateConfig
1416

17+
logging_config = StructLoggingConfig()
18+
1519
catalog = Catalog()
1620
catalog.add_folder("components")
1721

1822
compression_config = (CompressionConfig(backend="gzip", gzip_compress_level=9),)
23+
1924
cors_config = CORSConfig(allow_origins=["*"])
2025
csrf_config = CSRFConfig(secret="my-secret")
2126

@@ -30,21 +35,21 @@ async def index() -> Response:
3035

3136

3237
#
33-
@post(path="/feedback", exclude_from_csrf=True)
34-
async def feedback(request: HTMXRequest) -> Response:
38+
@post(path="/test1", exclude_from_csrf=True)
39+
async def test1(request: HTMXRequest) -> Response:
3540
message = "Feedback from HTMX and JinjaX components"
3641
return render("Feedback", message=message)
3742

3843

39-
@post(path="/feedback2", exclude_from_csrf=True)
40-
async def feedback2(request: HTMXRequest) -> Template:
41-
message = "Feedback from HTMX and Jinja2 tmplates"
44+
@post(path="/test2", exclude_from_csrf=True)
45+
async def test2(request: HTMXRequest) -> Template:
46+
message = "Feedback from HTMX and Jinja2 templates"
4247
return Template(template_name="feedback.jinja2", context={"message": message})
4348

4449

4550
#
4651
app = Litestar(
47-
route_handlers=[index, feedback, feedback2],
52+
route_handlers=[index, test1, test2],
4853
debug=True,
4954
csrf_config=csrf_config,
5055
cors_config=cors_config,
@@ -53,4 +58,10 @@ async def feedback2(request: HTMXRequest) -> Template:
5358
engine=JinjaTemplateEngine,
5459
directory=Path("templates"),
5560
),
61+
logging_config=logging_config,
62+
openapi_config=OpenAPIConfig(
63+
title="My API",
64+
version="1.0.0",
65+
root_schema_site="rapidoc",
66+
),
5667
)

components/ContactForm.jinja

Lines changed: 0 additions & 24 deletions
This file was deleted.

components/Feedback.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{#def message = "HI!" #}
2-
<h4 class="text-red-500 font-bold">{{message}}!</h4>
2+
<h4 class="text-red-500 font-bold">{{ message }}</h4>

components/Layout.jinja

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
<!DOCTYPE html>
33
<html lang="en">
44

5-
<head>
6-
<meta charset="UTF-8">
7-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8-
<title>{{ title }}</title>
9-
<script defer src="//cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
10-
<script src="//cdn.tailwindcss.com"></script>
11-
<link href="//cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.css" rel="stylesheet" />
12-
<script src="https://unpkg.com/[email protected]" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script>
5+
<head>
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>{{ title }}</title>
9+
<script defer src="//cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
10+
<script src="//cdn.tailwindcss.com"></script>
11+
<link href="//cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.css" rel="stylesheet" />
12+
<script src="https://unpkg.com/[email protected]" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script>
13+
</head>
1314

14-
</head>
15-
16-
<body class="bg-gray-800 text-yellow-500">
17-
{{ content }}
18-
</body>
15+
<body class="bg-gray-800 text-yellow-500">
16+
{{ content }}
17+
</body>
1918

2019
</html>

components/Welcome.jinja

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
{#def title = "Untitled", message #}
22

33
<Layout title=title>
4-
<h1 class="text-4xl">
5-
{{ message }}
6-
</h1>
4+
<h1 class="text-4xl">
5+
{{ message }}
6+
</h1>
77

8-
<div x-data="{ count: 0 }" class="mt-4 mb-4">
9-
<button x-on:click="count++"
10-
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">Alpine.js example</button>
8+
<div x-data="{ count: 0 }" class="mt-4 mb-4">
9+
10+
<button x-on:click="count++"
11+
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
12+
Alpine.js example
13+
</button>
1114

15+
<kbd x-text="count"
16+
class="px-2 py-1.5 text-xs font-semibold text-gray-800 bg-gray-100 border border-gray-200 rounded-lg dark:bg-gray-600 dark:text-gray-100 dark:border-gray-500" />
1217

13-
<kbd x-text="count"
14-
class="px-2 py-1.5 text-xs font-semibold text-gray-800 bg-gray-100 border border-gray-200 rounded-lg dark:bg-gray-600 dark:text-gray-100 dark:border-gray-500" />
18+
</div>
1519

16-
</div>
20+
<button hx-post="/test1" hx-target="#test1" type="button"
21+
class="text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center me-2 mb-2">
22+
HTMX example
23+
</button>
1724

18-
<button hx-post="/feedback" hx-target="#feedback" type="button" class="text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center me-2 mb-2">HTMX example</button>
25+
<div id="test1" class="mt-2 mb-2"></div>
1926

20-
<div id="feedback" class="mt-2 mb-2"></div>
27+
<button hx-post="/test2" hx-target="#test2" type="button"
28+
class="text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center me-2 mb-2">
29+
HTMX example 2
30+
</button>
2131

22-
<button hx-post="/feedback2" hx-target="#feedback2" type="button" class="text-white bg-gradient-to-br from-purple-600 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center me-2 mb-2">HTMX example 2</button>
23-
24-
<div id="feedback2" class="mt-2"></div>
32+
<div id="test2" class="mt-2 mb-2"></div>
2533
</Layout>

poetry.lock

Lines changed: 68 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ readme = "README.md"
77

88
[tool.poetry.dependencies]
99
python = "^3.12"
10-
litestar = {extras = ["standard"], version = "^2.5.4"}
10+
litestar = {extras = ["standard", "structlog"], version = "^2.5.4"}
1111
jinjax = "^0.30"
12+
icecream = "^2.1.3"
1213

1314

1415
[build-system]

0 commit comments

Comments
 (0)