flask 学习

最近学习flask框架,是照着图灵丛书《Flask Web开发》来学的。

照着第2章写了个简单的框架

#_*_coding:utf-8 _*_
from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return '<h1>hello</h1>'

@app.route('/hello')
def hello():
    return '<h2>hello,there</h2>'

@app.route('/user/<name>')
def user(name):
    return '<h2>hello,%s!<h2>' %name    
    

if __name__=='__main__':
    app.run(debug=True)
    

在自己电脑布置了virtualenv环境,通过它运行了程序

需要提一下,在首行加了  #_*_coding:utf-8 _*_    

文本才可以写中文,不然无法识别。

后面接着学习。

 

posted @ 2016-11-26 00:04  hanzhang  阅读(132)  评论(0编辑  收藏  举报