from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
- Import the
Flask
class and render_template
function from the Flask module. - Create a Flask application instance with
Flask(__name__)
. - Define a route for the root URL
'/'
using the @app.route
decorator. - Create a function (e.g.,
index()
) to handle the specified route. - Inside the function, use
render_template('index.html')
to render the HTML file named 'index.html'. - If the script is run directly (not imported), start the Flask development server with
app.run(debug=True)
.