python web框架 Flask(2)
from flask import Flask from flask import render_template from flask import request app=Flask(__name__) @app.route('/') def index(): return "hello,word" @app.route('/test') def test(): return "test!" @app.route('/post/<int:user_id>') def show_user(user_id): return "userid: %d" % user_id @app.route('/user/<username>') def print_user(username): return "username: %s" % username @app.route('/hello/<name>') def hello_name(name=None): return render_template('index.html',name=name) @app.route('/login',methods=['POST','GET']) def login(): error=None if request.method=='POST': if valid_login(request.form['username'], request.form['password']): return log_the_user_in(request.form['username']) else: error='Username/Password Error!' else: print "Login in" if __name__=='__main__': app.debug=True app.run(host='0.0.0.0')