pyramid框架 獲取接口請求參數

GET接口寫法1 
接口: 
https://ip:port/dashboard/create_jump_url?id_str=12345566

路由route.py: 

config.add_route('dashboardcreate_jump_url', '/dashboard/create_jump_url')

視圖函數view.py:

@view_config(route_name='dashboardcreate_jump_url', request_method='GET', renderer='json')
def dashboardcreate_jump_url(request):
    id_str = request.params["id_str"]

 

GET接口寫法2
接口: 
https://ip:port/dashboard/create_jump_url/12345566

路由route.py: 

config.add_route('dashboardcreate_jump_url', '/dashboard/create_jump_url/{id_str}')

視圖函數view.py:

@view_config(route_name='dashboardcreate_jump_url', request_method='GET', renderer='json')
def dashboardcreate_jump_url(request):
    id_str = request.matchdict['id_str']

 

POST接口 
接口: 
### 接口 https://ip:port/A/B
### 方法 POST
### request
``` json
{
   "begin_time":1589990400,  
   "end_time":1592555770,
   "type":0/1               
}

路由route.py:

config.add_route('AB', '/A/B')

視圖函數view.py:

@view_config(route_name='AB', request_method='POST', renderer='json')
def AB(request):
    reqdata = request.json_body
   
    begintime = reqdata["begin_time"]
    endtime = reqdata["end_time"]
    type = reqdata["type"]       

 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章