zoukankan      html  css  js  c++  java
  • python中bottle模块的使用

    1.简介

    2.示例

    2.1一个简单的bottle接口

     1 # -*- coding: utf-8 -*-
     2 
     3 from bottle import route, request, run
     4 import json
     5 
     6 feedbackdata = {'status': 'ok', 'data': 'I received the value'}
     7 
     8 
     9 @route('/getmsg')
    10 def start():
    11     radar = int(request.query.radar)
    12     station = int(request.query.station)
    13     print 'radar and station is: ', radar, station
    14     print type(radar)
    15     if radar == 4 and station == 1:
    16         return json.dumps(feedbackdata)
    17 
    18 run(host='127.0.0.1', port=8080, debug=False)

    2.2通过requests获取值

    1 # -*- coding: utf-8 -*-
    2 
    3 import requests
    4 # 通过url传递的参数
    5 payload = {'radar': 4, 'station': 1}
    6 r = requests.get('http://127.0.0.1:8080/getmsg', params=payload)
    7 print r.json()
    8 print r.content
    9 print r.text

    !!!

  • 相关阅读:
    html实现文件夹的上传和下载
    JQuery & Javascript
    JSP Scripting Element
    JSP Filter
    Oct22 实例测试
    JSP HTML error code
    Implicit Object in JSP
    JSP action elements
    JSP lifecycle
    Eclipse 配置Tomcat
  • 原文地址:https://www.cnblogs.com/jfl-xx/p/8081502.html
Copyright © 2011-2022 走看看