I am new to Django and Python and was wondering how I could read a tab dilimited file into a html table by modifying my views.py and then returning the separate columns as a variable and returning that variable through params and then changing my template.html page.
so for example
def index(request):
myfile = open (filename.txt)
for row in myfile:
list = row.rstrip().split('\t')
params = {
"first" = list[0]
}
return render(request, 'index.html', params)
something of this sort any help is greatly appreciated
My first recommendation is to use with
to open files:
with open('filename.ext', 'mode') as f:
Using with
automagically closes your file for you so you don't have to explicitly do so :)
Second, please visit: http://docs.python.org/3.3/library/csv.html#examples for a great explanation from the source.
The first example demos how to read your CSV file!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.