Simple setup to use django's template engine for non-django applications.
Project description
django-template-standalone
Simple setup to use django's template engine for non-django applications.
Install
pip install django-template-standalone
Usage
from django_template_standalone import render
from django_template_standalone import register_dirs
from django_template_standalone import render_template
msg = render("hello {{name}}, how are you?", {"name": "Cissie"})
assert msg == "hello Cissie, how are you?"
reigster_dirs("./templates/")
html = render_template("index.html", {"title": "This is an index Page"})
assert html == "<h1>This is an index Page</h1>"
Content of ./templates/index.html
is:
<h1>{{title}}</h1>
Methods
render(template_text, context)
: Render a template text with context.render_template(template_filename, context)
: Render a template file with context.reigster_dirs(*dirs)
: Add template dirs.register_apps(*apps)
: Add template apps.setup(template_dirs, apps)
: Setup django's template engine with template dirs and apps.
Note:
- When using
reigster_apps
method or usingapps
parameter insetup
method, there must be atemplates
sub-folder under the APP's root folder. - The
setup
method will be auto called in other functions, so you really don't need to call it manually.
Releases
v0.1.0 2021/11/30
- First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-template-standalone-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0447fb8ae20af4a9d8a5de701b303fc9f1b8f37d78105994fe73956e553bc16a |
|
MD5 | c6882a87dc85014deeb0b8fdc9021320 |
|
BLAKE2b-256 | e0a09fcbb87aee59f3628ca9b0aee081b76b7ea2222b2dc191262dfe175e439c |