Just learning python, Jinja and all, your help would be great!
My Python program pulls data and put it into list form. My goal is to display three parts of each line of data in an html table online. I tried to do this by using string replacement and html syntax. The 3 variable are supposed to be under the name, price, and quantity tabs. It came out like this:
Below is how I created the format. I'm sure the way I'm rendering the code writes exactly what I put, which is the html syntax, but I'm unsure of how to input the data so that the html syntax is recognized
card_list = []
card_info = "<tbody> \
<tr> \
<th scope='row'>1</th> \
<td>{0}</td> \
<td>{1}</td> \
<td>{2}</td> \
</tr> \
</tbody>".format(card_name, buy_price, quantity)
# 3 variables are one line of a list of data
card_list.append(card_info)
return card_list
In Django view.py, I render the list like this:
from Buylist.buy import get_data
data = get_data(ixalan)
def card_data(request):
return render(request, 'buylist/basic.html', {'content':data})
And the HtML Using Jinja looks like:
{% extends "buylist/header.html" %}
{% block content %}
<table class="table">
<thead class="thead-inverse">
<tr>
<th>#</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
# For loop getting data from card_data is here
{% for c in card_data %}
{{c}}
{% endfor %}
</table>
{% endblock %}
I would really appreciate any help! Thanks so much!
safe
, but moving all HTML to templates would be a better option. You can store your data list in the form of dictionaries and access them via dot in the template.