A thin wrapper around the Django templating system to render any string as a template. It provides an easy way to render any user inputted string as a regular django template.
Project description
django-string-renderer
A thin wrapper around the Django templating system to render any string as a template. It provides an easy way to render any user inputted string as a regular django template.
Requirements
This wrapper uses no models and requires no settings. There is no need to register this app in your INSTALLED_APPS.
This package uses type annotations and mypy to check those annotations.
This package is only tested against Python >= 3.5 and Django >= 1.11.
Usage
import stringrenderer
template_string = "Hello {{ recipient.first_name }} {{ recipient.last_name }}!"
renderer = StringTemplateRenderer(template_string)
rendered_content = renderer.render_template(context=dict(recipient=recipient_1), request=request)
rendered_content = renderer.render_template(context=dict(recipient=recipient_2), request=None)
When the first rendering request occurs on a given StringTemplateRenderer
instance, a Template
object is built from the string passed to __init__()
, and cached for the next rendering operations with other contexts.
You may check the template syntax ike this:
import stringrenderer
template_string = "Hello {{ recipient.first_name }} {{ recipient.last_name }}!"
is_valid, syntax_error = check_template_syntax(template_string)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-string-renderer-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b312a0de91e15b4743000bd641fad624cdc667ae5601e9da3e7702eb86e53db4 |
|
MD5 | c0a21af843935e48a2b4882969f33726 |
|
BLAKE2b-256 | d8ed78f40ce009a2583b0aed385c1817c311fc67312ffb6d0408f0ae62db92ae |
Hashes for django_string_renderer-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2ffc87b1d6e89db962aae7572b35df7e6cca2b4a400f9b481527e37ee6f8c4f |
|
MD5 | 8f32712117495166f583772b24d5b90d |
|
BLAKE2b-256 | 42f0b698feb51f24177f052e1bba077ed909f4ae280c29f98d5fe192175182be |