Hey,
I am trying to build an interface using django. This way i am learning django as well.
So i have completed web-poll tutorial and i tried something on my own.
My problem,
I have a file with following content.
# Stats
total_connections_received:2
total_commands_processed:1
instantaneous_ops_per_sec:0
rejected_connections:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
# Keyspace
db0:keys=6,expires=0
Now, i want to display the above content in a table from on the web interface.
Following is my directory structre where mysite is the root app and polls is the secondary app.
ravi@ravi-ThinkPad-X230:~/python/mysite$ tree
.
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
└── polls
├── admin.py
├── admin.pyc
├── __init__.py
├── __init__.pyc
├── models.py
├── models.pyc
├── static
│ └── polls
│ ├── images
│ │ └── images.jpg
│ └── style.css
├── templates
│ └── polls
│ ├── detail.html
│ ├── index.html
│ ├── results.html
│ └── table.html
├── test.py
├── test.pyc
├── tests.py
├── tests.pyc
├── urls.py
├── urls.pyc
├── views.py
└── views.pyc
7 directories, 29 files
following is my polls/templates/polls/table.html
{% if line %}
<table style="width:300px">
{% for x in line %}
<tr>
<td>{{ x }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>No polls are available.</p>
{% endif %}
following is my polls/views.py
from django.shortcuts import get_object_or_404, render
from django.http import Http404, HttpResponse, HttpResponseRedirect
from polls.models import Choice, Poll
from django.core.urlresolvers import reverse
from django.template import RequestContext, loader
from django.views import generic
from django.core.files import File
def table(request):
with open('/home/ravi/python/temp.txt', 'r') as f:
for line in f:
context = {'line': line}
return render(request, 'polls/table.html', context)
when it the url,
I get the following output,
but i want the output as each line of the file as a row in the table.
Any help.