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>>url:https://wiki.codepowered.com/wiki/How_to_Create_a_VirtualEnv]]. | ||
2 | |||
3 | [[In the virtualenv, install flask>>url:https://wiki.codepowered.com/wiki/How_to_add_libraries_to_a_virtualenv]], then try out this .py file. | ||
4 | |||
5 | {{{from flask import Flask | ||
6 | |||
7 | app = Flask(__name__) | ||
8 | |||
9 | @app.route('/', methods=['GET']) | ||
10 | def index(): | ||
11 | return 'Hi' | ||
12 | |||
13 | app.run() | ||
14 | }}} | ||
15 | |||
16 | Run this script [[in the virtualenv>>url:https://wiki.codepowered.com/wiki/How_to_Run_a_Python_Script_in_a_VirtualEnv]]. It will not exit. | ||
17 | |||
18 | Now you should be able to access [[http:~~/~~/localhost:5000/>>url:http://localhost:5000/]] in your web browser. |