-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental Django template loader.
- Loading branch information
Showing
3 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
from django.http import HttpRequest | ||
from django.template import Context, TemplateDoesNotExist | ||
from django.utils.module_loading import import_string | ||
|
||
from . import Element, render_node | ||
|
||
|
||
class _HTPYTemplate: | ||
def __init__(self, func: Callable[[Context | None, HttpRequest | None], Element]) -> None: | ||
self.func = func | ||
|
||
def render(self, context: Context | None, request: HttpRequest | None) -> str: | ||
return render_node(self.func(context, request)) | ||
|
||
|
||
class HTPYTemplates: | ||
def __init__(self, config: Any): | ||
pass | ||
|
||
def get_template(self, name: str) -> _HTPYTemplate: | ||
try: | ||
return _HTPYTemplate(import_string(name)) | ||
except ImportError: | ||
raise TemplateDoesNotExist(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters