Gestion des URL et ID avec Django
Bonjour,
Je développe un petit site en Django et je suis bloqué avec un certain type d'Url. En effet, je souhaiterai afficher une page en fonction d'un ID
Voici le code qui m'affiche une vue partielle
Code:
1 2 3 4
| views.py
def affiche_partiel(request, pk):
partiel=Formulaire.objects.all().filter(id=pk)
return render(request, 'blabla/affiche_partiel.html', {'affiche_partiel': partiel}) |
Voici le code HTML (en partie)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| {% if detail%}
<div id="wrapper">
<table cellpadding="0" cellspacing="0" border="0" class="sortable">
<thead>
<tr>
<th>Depart</th>
<th>Arriver</th>
<th>Date</th>
<th>Heure</th>
<th>Login</th>
</tr>
</thead>
{% for formulaire in detail.all %}
<tbody>
<tr>
<td>{{ formulaire.depart }}</td>
<td>{{ formulaire.arriver }}</td>
<td>{{ formulaire.date }}</td>
<td>{{ clegpg.heure }}</td>
<td>{{ formulaire.login }}</td>
<td><a href="detail/{{ formulaire.id }}/">{{ 'detail' }}</a></td>
</tr>
</tbody>
{% endfor %}
</table> |
En faite lorsque je clic sur "détail", j'aimerai etre redirigé vers la page "detail.html" afin d'afficher le résultat avec l'ID correspondant, un peu à la manière de:
Code:
http://www.developpez.net/forums/newthread.php?id=1
Voici mon fichier urls.py
Code:
1 2
| url(r'^affiche_partiel', views.affiche_partiel, name='affiche_partiel'),
url(r'^(?P<formulaire_id>[0-9]+)/$', views.detail, name='detail'), |
Merci