tags:

views:

40

answers:

1

Hi all,

Can you please give me a small piece of code where we display data from a table if any in Django.....

Please point me to a code that goes into views.py and template/index.html to diaply the table.............

Thanks....

+1  A: 

Read the Django tutorial. It shows, in 4 parts, the basics of this framework.

As for your question, a very quick example.

In views.py:

def display(request):
  return render_to_response('template.tmpl', {obj: models.Book.objects.all()})

In models.py:

class Book(models.Model):
  author = models.CharField(max_length = 20)
  title = models.CharField(max_length = 40)
  publication_year = models.IntegerField()

In template.tmpl:

<table>
<tr><th>author</th><th>title</th><th>publication year</th></tr>
{% for b in obj %}
<tr><td>{{ b.author }}</td><td>{{ b.title }}</td><td>{{ b.publication_year }}</td></tr>
{% endfor %}
</table>
kender
Thank u very much............U were a lot of help :)
Hulk