How can I make a Flask view publish just the raw HTML (unrendered) that was generated by app?
Flask uses the Jinja template library to render templates. In your application, you will use templates to render HTML which will display in the user's browser. In Flask, Jinja is configured to autoescape any data that is rendered in HTML templates.
Flask uses the Jinja template engine to dynamically build HTML pages using familiar Python concepts such as variables, loops, lists, and so on.
Try setting the mime type of the response to text/plain
using make_response
:
from flask import app, make_response, render_template
app = Flask(__name__)
@app.route('/')
def index():
resp = make_response(render_template('template.html'))
resp.mimetype = 'text/plain'
return resp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With