Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use Python on mustache template files
#1
EDIT:
Do not read this uber noob solutions bellow! I used it before I find out simple and user friendly Jinja. Greate tutorial about it is here.


To use mustache templating language with Python we need chevron.

pip install chevron

If you get some red errors try this:
pip install --user chevron

If you still get red errors, sorry I'm a NOOB.

Next, add chevron.exe to PATH, like pip message suggest.

Example template file (diviera.txt):
<title>{{title}}</title>
This is {{name}}!

Python code:
import chevron

strings = {'title': 'Fantastic title',
            'name':'Sparta'}

with open('diviera.txt', 'r') as f:
    fillup = chevron.render(f, strings)    

with open('diviera_final.txt', 'w') as nf:
    nf.write(fillup)
Messages In This Thread
Use Python on mustache template files - by Janusz - 12-17-2020, 11:28 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)