ajax

2018-12-13  本文已影响0人  学生时代的执念

from flaskimport Flask

from flaskimport render_template

import json

from flaskimport Response

from flaskimport request

app = Flask(__name__)

@app.route("/index/",methods=["GET"])

def index():

r = render_template("ajax1.html")

# render_template (渲染)

    return r

@app.route("/p/",methods=["POST"])

def p():

lst = [{"name":"zhang","age":13}]

j = json.dumps(lst)

r = Response(j)

r.headers = {"Content-Type":"application/json;charset=utf-8"}

return r

@app.route("/signup/",methods=["POST"])

def signup():

name = request.values["name"]

age = request.values["age"]

print("用户名=" + name)

print("密码=" + age)

d = {"msg":"注册成功",

        "date":{

"name":name,

            "age":age}

}

return json.dumps(d)

if __name__ =='__main__':

app.run()

上一篇 下一篇

猜你喜欢

热点阅读