0

Is it possible to use templates in Flask like in Bottle, without any external files? Just a template in a simple string variable. How would that work?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

2

Use flask.render_template_string() to render a template stored in a string.

from flask import render_template_string

return render_template_string(
    '<body>{{ greeting }}</body>',
    greeting='Hello, World!')
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343