I'm trying to run a Python script with HTML code embedded and it's not working. I'm want to execute a Python script and at the same time render the HTML which will be printed by the script.
app.py
:
#!/usr/bin/python2.6
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/briefing')
def briefing():
return render_template('briefing.html')
@app.route('/briefing/code')
def app_code():
return render_template('app_code.py')
if __name__ == '__main__':
app.run(debug=True)
app_code.py
:
https://i.stack.imgur.com/sIFFJ.png
When I access http://127.0.0.1:5000/briefing/code
the result is https://i.stack.imgur.com/iEKv2.png.
I know that what is happening is that I'm rendering as HTML and therefore the Python code inside of the file is not being interpreted.
How can I run the app_code.py
and at the same time, render the HTML from it?