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-2.0.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dot_js_py-2.0.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file dot_js_py-2.0.0.tar.gz.

File metadata

  • Download URL: dot_js_py-2.0.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.2 Darwin/22.4.0

File hashes

Hashes for dot_js_py-2.0.0.tar.gz
Algorithm Hash digest
SHA256 2009d6dd68db2cd6f526fae7598c1aa7d74d51722b7ad4d253b9c1dfee90016d
MD5 3ef7696991e9aaa8c2711f452d33ba07
BLAKE2b-256 570f54d6ac86a0c32201f4b12952d2a08b288edd85dbfaae7a0c91b13f7ad143

See more details on using hashes here.

File details

Details for the file dot_js_py-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: dot_js_py-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.2 Darwin/22.4.0

File hashes

Hashes for dot_js_py-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd4b8c17cce57d9280176073fb56003b5e00c898a6417264d26235cc6b6cdf19
MD5 ce889ebfeecba2af432b97ce119af35a
BLAKE2b-256 0fc9ce3ba290c913e55098119268cc84493e2615a699c7881809c45a56d0a4d8

See more details on using hashes here.

Supported by

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