I am trying out a Flask Tutorial on how to do something very basic but I cannot figure out how to reference the .html file in my Flask code in IPython/Windows setup.
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
names = [{'name' : 'Rebecca'}]
return render_template('layout.html', names=names, language='Python', lang=True, framework='Flask')
if __name__ == '__main__':
app.run()
I have the layout.html file saved to a directory on my C:Drive and in IPython would I need to do a change directory command prior to running the Flask code? IE, my .html file lives here:
%cd "C:\Users\Documents\Python\flask\static"
I get a long IPython error and at the bottom it seems to be telling me the .html file cannot be found. Any ideas? Thanks-
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: layout.html
127.0.0.1 - - [10/Apr/2018 11:54:09] "GET / HTTP/1.1" 500 -
UPDATE
This is the .html code:
<!DOCTYPE html>
<html>
<head>
<title>Flask Templates</title>
</head>
<body>
<h1>Hello, {{ names.name }}</h1>
{% if lang %}
<p>The language your using is {{ language }}.</p>
{% else %}
<p>The framework your using is {{ framework }}.</p
{% endif %}
</body>
</html>