question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Templating in Brython?

See original GitHub issue

Hello guys, and congratulations for this great work: it’s a real pleasure to finally work with a comfortable language in the browser…

My question is about templating: in almost all apps I build client side, I need to format templates (walk over dicts, check conditions, replace values…).

Here is an example of such a template I used to code with Riot.js:

<ul>
    <li each={ tag in tags }>{ tag.text }</li>
</ul>

On server side Python, I usually use Jinja to achieve this.

How do you proceed in Brython code? Python’s string format() is a very limited solution (no loops, no conditions…). Importing Jinja in Brython program seems touchy…

Thank you very much in advance!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
benjaminrigaudcommented, Jul 15, 2017

I started evaluating Jinja2 on Brython: a few issues have been opened (and resolved) in the past weeks. I’ll continue my work as soon as possible.

A fork will be required: some features (like bytecode cache) will not be compatible with Brython.

1reaction
PierreQuentelcommented, Dec 23, 2017

After many trials and errors , I have a working version of the browser.template module (see the documentation). It is vaguely inspired by vue.js.

I have also added a version of the “sort table” demo using it, is is much more concise than the version with browser.html to generate HTML code.

Feedback is very much welcome. I will also post a message on the Google group.

Read more comments on GitHub >

github_iconTop Results From Across the Web

module browser.template - Brython documentation
The module template allows to dynamically generate some elements in a page, by including Python code blocks or expressions inside the HTML code....
Read more >
Creating a document - Brython
Hello world ! Insert content in an element · HTML markup (bold,italic...) HTML table · Bind and unbind events · Handle options in...
Read more >
interpreter - Brython documentation
This module provides classes to open a Python interactive interpreter in a page. It is used by the console and the editor of...
Read more >
Problem - Brython documentation
Problem. Validate the content of a form before sending it to the server. Solution. In the form below we want to check that...
Read more >
Syntax, keywords and built-in functions - Brython documentation
Brython supports all the keywords and functions of the Python version with the same version number. Here are a few features and limitations...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found