How to collect a record by a parameter python
<p>Python source :</p>

<pre><code>@app.route('/pret/&lt;int:idPret&gt;', methods=['GET'])
def descrire_un_pret(idPret):

    j = 0

    for j in prets:
        if prets[j]['id'] == idPret:
            reponse = make_response(json.dumps(prets[j],200))
            reponse.headers = {"Content-Type": "application/json"}
            return reponse
</code></pre>

<p>I would like to retrieve a record in the <code>prets</code> list by the <code>idPret</code> parameter. Nevertheless I get an error:</p>

<pre><code>TypeError: list indices must be integers, not dict
</code></pre>

<p>You are mistaking Python's for behavior for Javascript's. When you do 
<code>for j in prets:</code> in Python, the contents of <code>j</code> are already the elements in <code>pretz</code>, not an index number.</p>

python flask