不論POST請求還是GET請求都支持在 URL 中添加變量,可以選擇性的加上一個轉換器,為變量指定數據類型。
@history_alarm.route('/test/<int:post_id>', methods=['POST'])
def test(post_id):print(f"參數類型為:{type(post_id)}")in_json = request.get_json()return f'Post {post_id}'
@history_alarm.route('/test/<int:post_id>', methods=['GET'])
def test(post_id):print(f"參數類型為:{type(post_id)}")return f'Post {post_id}'
轉換器: