Flask/Static Pages
< Flask
This lesson shows how to display static content pages using Flask.
Readings
Multimedia
Activities
- Add a static folder to Flask.
- Create a folder named
staticin your Flask application folder.
- Create a folder named
- Add an index.html file to the static folder.
- Create a file named
index.htmlin thestaticfolder. - Add any standard HTML you'd like to the
index.htmlfile, or just addHello world!
- Create a file named
- Create or modify the Flask application page.
- Modify main.py or app.py to include the following code:
import flaskapp = flask.Flask(__name__)@app.route('/')def root():return app.send_static_file('./index.html')if __name__ == "__main__":app.run(host='0.0.0.0', port=5000)
- Run the program.
- Refresh the output window or open a browser window to http://localhost:5000.
- Stop the program.
- Modify main.py or app.py to include the following code: