2009-12-08 9 views

Répondre

9

Read the Django tutorial. Il montre, en 4 parties, les bases de ce cadre. En ce qui concerne votre question, un exemple très rapide.

En views.py:

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

En models.py:

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

En 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> 
+0

Merci u beaucoup ....... ..... U étaient beaucoup d'aide :) – Hulk

Questions connexes