Skip to content

Commit b540d12

Browse files
refactor(templating): update template context and middleware
- Add template_context import to __init__.py - Improve TemplateEngine class structure - Update TemplateContextMiddleware to use base_app.url_for
1 parent 7204db6 commit b540d12

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

nexios/templating/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from nexios.config import MakeConfig, get_config
1212
from nexios.http.response import HTMLResponse
1313
from nexios.types import Request
14+
from .middleware import template_context
1415

1516
engine: Union["TemplateEngine", None] = None
1617

@@ -30,6 +31,7 @@ def __init__(
3031
custom_filters: Dict[str, Callable[[Any], Any]] = {},
3132
custom_globals: Dict[str, Any] = {},
3233
):
34+
3335
super().__init__(
3436
{
3537
"template_dir": template_dir,
@@ -67,12 +69,12 @@ def setup_environment(self, config: Optional[TemplateConfig] = None):
6769
lstrip_blocks=self.config.lstrip_blocks,
6870
)
6971

72+
7073
config_ = self.config.to_dict()
7174
if config_.get("custom_filters"):
7275
self.env.filters.update(config_["custom_filters"])
7376
if config_.get("custom_globals"):
7477
self.env.globals.update(config_["custom_globals"])
75-
7678
engine = self
7779

7880
async def render(

nexios/templating/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def __call__(
4242
context.update(
4343
{
4444
"request": request,
45-
"url_for": request.app.url_for,
45+
"url_for": request.base_app.url_for,
4646
"csrf_token": request.state.csrf_token,
4747
}
4848
)

0 commit comments

Comments
 (0)