How to serve a HTML file using python flask

Last modified by Leon Poon on 2018/12/24 21:03

First, make sure that your flask app is working like inĀ How to serve a webpage using python flask.

Then, create your HTML file. Your HTML file must be in the same directory as your flask app python file.

Change your flask app python file to do send_from_directory instead of just saying hi. Use the name of the HTML file if it is not test.html:

from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route('/', methods=['GET'])
def m():
       return send_from_directory('', 'test.html')

app.run()
Tags:
Created by Leon Poon on 2018/12/24 17:49
    

Need help?

If you need help with XWiki you can contact: