Home > Mobile >  How to output an html file in flask
How to output an html file in flask

Time:05-25

I want to know how to output in the screen an html file. I have a route function and i want to display html to a website

@app.route('/')
def index():
   return "hi"

CodePudding user response:

Welcome to stack overflow!

To render an html template in flask first you must create a folder named templates. The folder must be in the same directory as your main file (where the app runs)

Then create a html file in the templates folder. You can call it whatever you want, I will call it index.html

Then add this code to your route:

from Flask import render_template

@app.route('/')
def index():
   return render_template('index.html')

CodePudding user response:

Here you go, hope this helps!

import Flask
@app.route('/')
def index():
    return flask.send_from_directory(".", path="index.html")
  • Related