Is there a way to pass HTML code as a string in python/flask rather than render template HTML file in a directory?
for example
from flask import Flask, render_template app = Flask(__name__) @app.route('/') def home(): return render_template('index.html') # Instead of giving file path I want to pass HTML code directly if __name__ == '__main__': app.run()
I guess you mean something like this:
from flask import Flask app = Flask(__name__) HTML_AS_TEXT = """<p>hello world</p>""" @app.route('/') def home(): return HTML_AS_TEXT if __name__ == '__main__': app.run()
2.1m questions
2.1m answers
60 comments
57.0k users