Jinja2 - list of dictionaries to html table with links

z3roCoo1
Conversationalist

Jinja2 - list of dictionaries to html table with links

A good while while ago I managed to fudge the Catalyst_to_Meraki_Migration_tool into a tool that run two very specific reports that I had hard coded for a particular organisation.

I've now got round to making something a bit more general purpose. However I'm failing at the first hurdle. The landing page will prompt for the users API key (I know, insecure - I will move to a db with user profiles later) in a form with a button to display the organisations they have access to.

 

Here's the code for the route this directs to:

 

 

@app.route('/org_list', methods=["POST"])
def org_list():
    import meraki

    #API_KEY = session["api"]

    dashboard = meraki.DashboardAPI(API_KEY, print_console=False, suppress_logging=True)

    session['orgs'] = dashboard.organizations.getOrganizations()
    return render_template("org_list.html", my_list=session['orgs'])

 

 

Template for org_list.html:

 

{% extends 'base.html %}

{% block body %}
<h4>Choose an organisation to view jobs</h4>
<table id="data" class="table table-striped">
    <thead>
      <tr>
        <th>Customer</th>
        <th>API</th>
        <th>Cloud Region</th>
        <th>Licensing</th>
      </tr>
    </thead>
    <tbody>
    {% for org in my_list %}
    <tr>
        <td><a href="https://127.0.0.1:5000/job_list.html?id={{org['id']}} target=_self">{{org['name']}}</a> }}</td>
        <td>{{ org['api']['enabled'] }}</td>
        <td>{{ org['cloud']['region']['name'] }}</td>
        <td>{{ org['licensing']['model'] }}</td>
    </tr>
    {% endfor %}
</tbody>
</table>
</div>
{% endblock %}

 

 

The error I'm getting is;

 

jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got 'id'

 

My google-fu is failing me so here I am.

0 Replies 0
Get notified when there are additional replies to this discussion.