zoukankan      html  css  js  c++  java
  • 初试Flask

    #coding=utf-8
    
    #服务器端代码  5
    from flask import Flask,request,json
    
    app = Flask(__name__)
    @app.route('/success/<name>')
    def success(name):
        return 'welcome %s'%name
    
    @app.route('/login',methods = ['POST','GET','DELETE'])
    def login():
        if request.method == 'POST':
            # return 'you are a post!'  #对应5.1
    
            # return '{"key": "I am a boy!!!"}' #对应5.2
    
            browser_type = request.headers.get("user-agent")#对应5.3
            return 'your header is :' + browser_type#对应5.3
    
        elif request.method == "DELETE":
            return "you are a delete!"
        else:
            return "you are a get!"
    if __name__ == '__main__':
        app.run(debug = True)
    #coding=utf-8
    
    import requests
    "启动5服务器,然后在启动5.1,可以查看服务器返回结果" 
    "复杂的话可能是去数据库里进行操作,返回一些结果"
    
    r = requests.get('http://127.0.0.1:5000/login')
    print("get:",r.text)
    
    r = requests.post('http://127.0.0.1:5000/login')
    print("post:",r.text)
    
    r = requests.delete('http://127.0.0.1:5000/login')
    print("delete:",r.text)
    #coding=utf-8
    
    import requests,json
    "启动5服务器,然后在启动5.2,可以查看服务器返回结果"
    "复杂的话可能是去数据库里进行操作,返回一些结果"
    
    
    r = requests.post('http://127.0.0.1:5000/login')
    
    print(r.json()) #自动将返回的json串,转换成字典
    print(type(r.json()))
    #coding=utf-8
    
    import requests,json
    "启动5服务器,然后在启动5.3,可以查看服务器返回结果"
    "复杂的话可能是去数据库里进行操作,返回一些结果"
    
    url = 'http://127.0.0.1:5000/login'
    headers = {'user-agent':'my-app/0.0.1'}
    r = requests.post(url,headers=headers)
    print(r.text)
  • 相关阅读:
    关于自定义UICollectionViewLayout的一点个人理解<一>
    自定义进度条
    iOS 无限轮播图的两种实现
    图片的拉伸
    关于plist文件
    加载gif图过渡效果
    关于textView的字数限制
    php-fpm服务启动脚本
    转载:PHP支付宝接口RSA验证
    将博客搬至CSDN
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/14120072.html
Copyright © 2011-2022 走看看