0x01 Essay

In the past time I ofen used Thinkphp for my web develop. Today I received a develop requirement where invoking a python script. I took this opportunity to try Flask. Bear in mind.

0x02 A easy Flask Web Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# /bin/python
from flask import Flask, redirect, url_for, render_template

app = Flask(__name__)

@app.route('/')
def index():
return "my first flask"

@app.route('/testvar/<var>')
def testvar(var):
return "This ia my variety: %s" %var

# Flask will look up template file in folder templates
# Like this:
# /application.py
# /templates
# /hello.html
@app.route('/testemplate/<route>')
def testemplate(route):
return render_template('hello.html', route=route)

@app.route('/testredirect/')
def testredirect(route):
return redirect('http://www.google.com' ,code=302)