Flask,传递词典列表,获取字符串

时间:2014-11-20 02:34:40

标签: python python-2.7 flask

我正在学习烧瓶,并试图将字典列表传递给重定向。命令request.args.getlist(list_of_dictionaries返回一个字符串列表。我很难理解如何将它们作为词典。

以下是我的代码:

a = {'length': '40', 'type': 'phone', 'name': 'Fax', 'label': 'Fax'}
b = {'length': '255', 'type': 'string', 'name': 'Name', 'label': 'Name'}
list_of_dictionaries = [a,b]
listOfObjects = ['Account','Opportunity','Lead']

@app.route('/found', methods=['GET','POST'])
def found():
  keys = request.args.getlist('keys')
  obj = request.args.getlist('obj')
  return render_template("found.html",keys=keys,obj=obj)

@app.route('/finder', methods=['GET','POST'])
def finder():
  if request.method == 'POST'
    return redirect(url_for('clientfound',keys=list_of_dictionaries,obj=listOfObjects))
  else: 
    return render_template('base.html')

1 个答案:

答案 0 :(得分:0)

也许你可以简单地使用request.args.get()然后使用json.loads