I have a simple Flask application with just one table. So python code is irrelavantly simple:
@app.route('/')
def home():
items = long_db_request()
return render_template("index.html", items=items)
@app.route('/extended')
def extended():
return render_template("animals.html")
And items is a huge JSON object.
I created a table which reflects that data:
<table>
<tr>
<th style="text-align:center">id</th>
<th style="text-align:center">creation time</th>
<th style="text-align:center">name</th>
<th style="text-align:center">animals</th>
<th style="text-align:center">number</th>
</tr>
{% for item in items %}
<tr>
<td> {{ item.id }} </td>
<td> {{ item.time }} </td>
<td>
<a href="{{url_for('extended', name=item.id )}}"> {{ item.name }} </a>
</td>
<td> {{item.group}} </td>
<td>{{ item.group|length }}</td>
</tr>
{% endfor %}
</table>
As you can see, column animal contains a lof of object which makes it all difficult to percieve. I want it to be like this
which is a lot easier to get. And show animals
is a link to another page, where a pure json exists.
How can I achieve this?
I followed the doc of jinja2 and Flask and found method url_for() but in that case I have to pass all my json in query which is unacceptable..
How can I jump from first image to exellent nice view of the second one?
working code with the first picture is place here
Thank you very much in advance!
P.S. I only saw one question here with rellevant topic, but it does not help me
Instead of passing all the animals (e.g. cats) from one view to another, just pass the category cats
to the next page.
The view function for the next page then selects all cats from the json, and passes the cats
then to the detailed view.
So, on you overview page, you render links like species.html?cats
(and so on), and when somebody clicks on these links the view function selects all cats, and then passes them into a render_template("species.html", species=cats)
view.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments