标签:
Python的web框架有很多:
Flask,Django,Zope2,Web.py,Web2py,Pyramid,Bottle, Tornado。。。
Flask 轻量级,比较简单
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run()
例子
from flask import Flask from flask import request app = Flask(__name__) @app.route(‘/‘, methods=[‘GET‘, ‘POST‘]) def home(): return ‘<h1>Home</h1>‘ @app.route(‘/signin‘, methods=[‘GET‘]) def signin_form(): return ‘‘‘<form action="/signin" method="post"> <p><input name="username"></p> <p><input name="password" type="password"></p> <p><button type="submit">Sign In</button></p> </form>‘‘‘ @app.route(‘/signin‘, methods=[‘POST‘]) def signin(): # 需要从request对象读取表单内容: if request.form[‘username‘]==‘admin‘ and request.form[‘password‘]==‘password‘: return ‘<h3>Hello, admin!</h3>‘ return ‘<h3>Bad username or password.</h3>‘ if __name__ == ‘__main__‘: app.run()
标签:
原文地址:http://www.cnblogs.com/roronoa-sqd/p/4912101.html