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"]       

 

 

你可能感兴趣的:(pyramid)