Patrom

59 views
Skip to first unread message

frederic kavita

unread,
Jul 8, 2017, 7:12:12 AM7/8/17
to brython
Hi pierre  patrom  works with only a python environment or in a JavaScript environment is enough


thanks

https://github.com/PierreQuentel/patrom

Pierre Quentel

unread,
Jul 9, 2017, 4:57:47 PM7/9/17
to brython
Hi Frederic,

You can actually use patrom in the browser :

<html>
<head>
<meta charset="utf-8">

<script src="/src/brython.js"></script>
<script src="/src/brython_stdlib.js"></script>

</head>
<body onload="brython(1)">
<script type="text/python">
import patrom
from browser import document

document.html = patrom.render("test.tmpl", name="pierre")
</script>
</body>
</html>

 
with this in file test.tmpl :

Votre nom est <py expr="name"/>
<br>
<ul>
<py code="for i in range(5, 10):">
    <li><py expr="i" />
</py>
</ul>


But it takes quite a long time because of the many imports needed. In a browser we have a built-in HTML parser, and since patrom templates are pure HTML, this parser can be use instead of html.parser in the Python library.

In the latest versions in the repository I have added a still experimental module simply called browser.template ; example :

<html>
<head>
<meta charset="utf-8">

<script src="/src/brython.js"></script>

</head>
<body onload="brython(1)">

<script type="text/python">
from browser import document, template

document['result'].html += template.Template("test.tmpl").render(name="Pierre")
</script>

<div id="result"></div>
</body>
</html>


frederic kavita

unread,
Jul 11, 2017, 7:42:11 AM7/11/17
to brython
Ok donc il faut que je telecharge la dernière version.
je vais teste ça

je vais creer un blog pour brython en français pour montre les posibilté de brython

a+ 
Reply all
Reply to author
Forward
0 new messages