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_appsmethod or usingappsparameter insetupmethod, there must be atemplatessub-folder under the APP's root folder. - The
setupmethod 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.
Release files for django-template-standalone 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-template-standalone-0.1.0.tar.gz | 4.3 kB | Details |
Release files / django-template-standalone-0.1.0.tar.gz
| Download URL | django-template-standalone-0.1.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0447fb8ae20af4a9d8a5de701b303fc9f1b8f37d78105994fe73956e553bc16a
|
|
BLAKE2b-256 checksum How to use checksums |
e0a09fcbb87aee59f3628ca9b0aee081b76b7ea2222b2dc191262dfe175e439c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|