Wiki source code of How to serve a HTML file using python flask
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | First, make sure that your flask app is working like inĀ [[How to serve a webpage using python flask>>url:https://wiki.codepowered.com/wiki/How_to_serve_a_webpage_using_python_flask]]. | ||
| 2 | |||
| 3 | Then, create your HTML file. Your HTML file must be in the same directory as your flask app python file. | ||
| 4 | |||
| 5 | 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: | ||
| 6 | |||
| 7 | {{{from flask import Flask, send_from_directory | ||
| 8 | |||
| 9 | app = Flask(__name__) | ||
| 10 | |||
| 11 | @app.route('/', methods=['GET']) | ||
| 12 | def m(): | ||
| 13 | return send_from_directory('', 'test.html') | ||
| 14 | |||
| 15 | app.run() | ||
| 16 | }}} |