-
Notifications
You must be signed in to change notification settings - Fork 12
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
64 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,30 @@ | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
from django.http import HttpRequest | ||
from django.template import Context, TemplateDoesNotExist | ||
|
||
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: | ||
from django.utils.module_loading import import_string | ||
|
||
try: | ||
func = import_string(name) | ||
except ImportError: | ||
raise TemplateDoesNotExist(name) | ||
|
||
return _HTPYTemplate(func) |
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