Thursday, April 24, 2014

Re: Reading from a file and displaying into a table on the web app.

Den 24/04/2014 kl. 16.46 skrev Ravi Hemnani <raviiihemnani@gmail.com>:

> def table(request):
> with open('/home/ravi/python/temp.txt', 'r') as f:
> for line in f:
> context = {'line': line}

Here you are ovwewriting 'content' on every iteration. When the loop exits, only the last line in the file will be in context. You want something like this instead:

def table(request):
with open('/home/ravi/python/temp.txt', 'r') as f:
context = {'lines': f.readlines()}


Erik

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8580A3DB-2C1E-4DDF-A6CA-D2AF89A32B44%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment