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')

 

posted @ 2014-03-21 16:38  墨迹哥's  阅读(232)  评论(0编辑  收藏  举报