4
How do I render the data of a arquivo.txt
in a Django template?
contents of the archive:
1;'one';'foo'
2;'two';'bar'
I return in the template
1 - one - foo
2 - two - bar
Any hint where I start?
Following the website http://www.coderholic.com/parsing-csv-data-in-python/
I tried the following:
def display_text_file():
with open('output.csv', 'rt') as f:
r = csv.reader(f, delimiter=';')
fields = r.next()
for row in r:
items = zip(fields, row)
item = {}
for (name, value) in items:
item[name] = value.strip()
Now how do I return this in the view context to iterate for the values in the template?
I tried to
{% for line in lines %}
<p>{{ line.id }}</p>
{% endfor %}
It’s actually a TXT anyway.
– Regis Santos
Are you sure you want to keep the dice in CSV, instead of pushing to a SGBD?
– user25930
Yes, I need to test site before I go up to production.
– Regis Santos
...the implication is that you do not have a test database for local development?
– user25930
The intention of this line and the following is to build a dictionary using the first line of the CSV as the "header" of the "spreadsheet".
– user25930
that’s right.....
– Regis Santos