2

Both template engines use {{ }} tags. I'm trying to serve an HTML file dynamically in BottlePy so that I can dynamically source javascript files, but this HTML file has Handlebars templates all over it. Any ideas on how to get around this? I've heard of this problem with other frameworks (Like Angular and Django) but I'm not sure if the same fix applies here.

Some ideas I've come up with are:

  1. Change the tag of one of the template engines (don't know if you can with these)
  2. Split up the HTML file into multiple parts and dynamically include them (might work but isn't my first choice)

If I could accomplish #1 that would be awesome, but after a bit of googling I'm not sure it's possible. I am open to using a template engine other than SimpleTemplate, so long as bottlepy supports it. #2 sacrifices some loading speed which is the driving force of this whole problem anyway, so I'd rather not do that if possible.

Please let me know if the problem is unclear and I can explain it better. Thanks for your time!

MattM
  • 1,159
  • 1
  • 13
  • 25

2 Answers2

1

Good question. I haven't found a way to do precisely what you're asking, but a simple (?) alternative might be to use jinja2 (or mako) templates instead of Bottle's SimpleTemplate.

I've used jinja2 for templating with much success, and it looks like it has decent escaping to help you:

http://jinja.pocoo.org/docs/templates/#escaping

(Plus, jinja2 templates have a much richer feature set without much more complexity, so in the long run you might benefit from the switch in other ways.)

Community
  • 1
  • 1
ron rothman
  • 17,348
  • 7
  • 41
  • 43
1

Bottle supports jinja, in which you can escape {{

waitingkuo
  • 89,478
  • 28
  • 112
  • 118