Skip to main content

A python implementation of the famous js template engine. doT.js.

Project description

doT.py

A python implementation of the famous js template engine. doT.js. http://olado.github.io/doT/index.html. It do excetly the same thing as doT.js except written in python. Thus, it can be used in python web framework.

doT.py compile the template to a pure javascript function in server side; therefore client side can evaluate the template later without any dependency. Which means it saves the time for client to load template engine and to load template file. In short, doT.py allows using client side template tech without include a template engine in client side.

Installation

pip install doT-js-py

Here is an example:

Use client side template

<html>
<!-- load template engine -->
<script type="text/javascript" src="doT.js"></script>
<div id="container">
<script type="text/javascript">
     // Compile template function
     var tempFn = doT.template("<h1>Here is a sample template {{=it.foo}}</h1>");
     var resultText = tempFn({foo: 'with doT'});
     document.getElementById('container').innerHtml = resultText;
</script>
</html>

Use doT.py, you write:

<html>
<!-- without loading template engine -->
<div id="container">
<script type="text/javascript">
     // Compile template function
     var tempFn = {{ js_template('<h1>Here is a sample template {{=it.foo}}</h1>') }};
     var resultText = tempFn({foo: 'with doT'});
     document.getElementById('container').innerHtml = resultText;
</script>
</html>

it will automatically compiled to

<html>
<!-- without loading template engine -->
<div id="container">
<script type="text/javascript">
     // Compile template function
     var tempFn = function anonymous(it) { var out='"<h1>Here is a sample template '+(it.foo)+'</h1>"';return out; };
     var resultText = tempFn({foo: 'with doT'});
     document.getElementById('container').innerHtml = resultText;
</script>
</html>

Django Support:

Jinja2 Support:

Commandline Support:

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

dot-js-py-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

dot_js_py-1.0.0-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dot-js-py-1.0.0.tar.gz.

File metadata

  • Download URL: dot-js-py-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.6 Darwin/22.1.0

File hashes

Hashes for dot-js-py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 284e7b16d0eef33f99c42fe9051e8a4bde810c9ec979ed6de898b263be6f71be
MD5 2fe6cc12022abd844594f125b333d0a8
BLAKE2b-256 8f5ac6519d4d6a7bb952c4790c59a9226dbec5ede878f4e1287042827415786e

See more details on using hashes here.

File details

Details for the file dot_js_py-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: dot_js_py-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.6 Darwin/22.1.0

File hashes

Hashes for dot_js_py-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e3145c8bb2f0b9110bc3a576a25a894574a080015f2fc02989dc6ea7477cef79
MD5 d7d2a345093146c472a4b676296db2c5
BLAKE2b-256 1f9f27fe61129300a1dab88f65a679eb5d8ba0231bbc49d40877377bdf1e1cd7

See more details on using hashes here.

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