Skip to main content

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

django-string-renderer-0.1.1.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

django_string_renderer-0.1.1-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page