2017-05-05 73 views
-2

我想在URL中传递多个参数,但只有一个参数正在接受。我使用了URL curl -i http://localhost:5000/details_page/api/v1.0/recommendation?content_id=SINGTEL_movie_22937&category=details_page,但只有content_id正在通过。在URL中传递多个参数与烧瓶

@app.route('/details_page/api/v1.0/recommendation', methods=['GET']) 
def recommendation(): 
    category = request.args.get('category') 
    content_id = request.args.get('content_id') 
    print(content_id) 
    print(category) 
    return(content_id,category) 
    if (category !='details_page'): 
     abort(404) 
    contents = cl.details_page(content_id)#goes to my logic 
    return(jsonify({'content_id':contents}), 201) 

回答

0

我得到了答案。我与我的网址有问题。使用curl时,url应该在双引号内。

curl -i http://"localhost:5000/details_page/api/v1.0/recommendation?content_id=SINGTEL_movie_22937&category=details_page" 
+0

考虑接受你的自己的答案。 –

0

我没有在你的代码,你正在返回的API所以它不打印,你是否有两个变量把它作为字符串或以JSON格式

串一个小的变化

app = Flask(__name__) 

@app.route('/details_page/api/v1.0/recommendation', methods=['GET']) 
def recommendation(): 
    category = request.args.get('category') 
    content_id = request.args.get('content_id') 
    print(content_id) 
    print(category) 
    return "{},{}".format(category, content_id)#changed this line 
    if (category !='details_page'): 
     abort(404) 
    contents = cl.details_page(content_id)#goes to my logic 
    return(jsonify({'content_id':contents}), 201) 
#from app import app 

字典

@app.route('/details_page/api/v1.0/recommendation', methods=['GET']) 
def recommendation(): 
    category = request.args.get('category') 
    content_id = request.args.get('content_id') 
    print(content_id) 
    print(category) 
    return jsonify(
       category= category, 
       content_id= content_id 
      ), 200 
    if (category !='details_page'): 
     abort(404) 
    contents = cl.details_page(content_id)#goes to my logic 
    return(jsonify({'content_id':contents}), 201) 
#from app import app 
+1

我得到了输出。当我们使用curl时,我们需要在URL中使用双引号。这是问题所在。谢谢你的帮助。 :) –

+0

是你是对的,但如果内容类型设置为JSON瓶,那么你必须jsonify返回你不能返回两个变量,所以在你的情况下,你把url在字符串,所以它的返回字符串 –