Wiki source code of How to serve a webpage using python flask
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | First, [[set up a virtualenv>>doc:Main.How to Create a VirtualEnv.WebHome]]. | ||
2 | |||
3 | [[In the virtualenv, install flask>>doc:Main.How to add libraries to a virtualenv.WebHome]], then try out this .py file. | ||
4 | |||
5 | {{code language="python"}} | ||
6 | from flask import Flask | ||
7 | |||
8 | app = Flask(__name__) | ||
9 | |||
10 | @app.route('/', methods=['GET']) | ||
11 | def index(): | ||
12 | return 'Hi' | ||
13 | |||
14 | app.run() | ||
15 | {{/code}} | ||
16 | |||
17 | Run this script [[in the virtualenv>>doc:Main.How to Run a Python Script in a VirtualEnv.WebHome]]. It will not exit. | ||
18 | |||
19 | Now you should be able to access [[http:~~/~~/localhost:5000/>>url:http://localhost:5000/]] in your web browser. |