I'm running Django 1.10 on Mac OS X.
I'm trying to put some links in my templates but I got a NoReverseMatch Error in both templates.
The error looks like this : NoReverseMatch at /kfet/
with the following sentence :
Reverse for 'interface' with arguments '()' and keyword arguments '{'id_ienkli': ''}' not found. 1 pattern(s) tried: ['kfet/interface_du_klient/(?P<id_ienkli>\\d+)$']
Here is the urls.py in my app :
#-*- coding: utf-8 -*-
from kfet import views
from django.conf.urls import url
from . import views
from kfet.models import klient
from django.urls import reverse
urlpatterns = [
url(r'^$', views.accueil, name='accueil'),
url(r'^interface_du_klient/(?P<id_ienkli>\d+)$', views.interface_du_klient, name='interface'),
url(r'^date$', views.date_actuelle),
url(r'^achat/(?P<id_bouffon>\d+)/(?P<id_ach>\d+)$', views.achat,name='achat')
]
Here is my views.py :
#-*- coding: utf-8 -*-
from django.http import HttpResponse
from django.shortcuts import render
from kfet.models import klient,achetables
from django.shortcuts import get_object_or_404
from django.urls import reverse
from datetime import datetime
def date_actuelle(request):
return render(request, 'kfet/date.html', {'date': datetime.now()})
def accueil(request):
liste_tokards=klient.objects.all()
return render(request, "kfet/accueil.html",{'liste_tokards': liste_tokards} )
def interface_du_klient(request,id_ienkli):
produits=achetables.objects.all()
klient_selec=get_object_or_404(klient, id_klient=id_ienkli)
if id_ienkli==0:
return redirect('accueil')
else :
render(request, "kfet/interface_du_klient.html", {'client': klient_selec}, {'liste_produits' : produits})
def achat(request,id_bouffon,id_ach):
klient_selec=get_object_or_404(klient, id_klient=id_ienkli)
if id_ach==0:
return redirect('interface_du_klient', id_ienkli=id_bouffon)
else:
klient_selec.acheter(id_ach)
return render(request, "kfet/interface_du_klient.html", {'client': klient_selec}, {'liste_produits' : produits})
Here is my interface_du_klient.html :
<h1>Bienvenue sur le site de la KFet !</h1>
Choisir un klient à faire payer !
<li><a href="{% url "kfet.views.accueil"%}">Retour accueil</a></li>
<li><a href="{% url "achat" id_bouffon=client.id_klient id_ach=1 %}">Acheter bière 33cl</a></li>
<li><a href="{% url "achat" id_bouffon=client.id_klient id_ach=2 %}">Acheter bière 25cl</a></li>
<li><a href="{% url "achat" id_bouffon=client.id_klient id_ach=3 %}">Acheter pinte Blondi</a></li>
And finally here is my accueil.html :
<h1>Bienvenue sur le site de la KFet !</h1>
Choisir un klient à faire payer!
{% for ptite_frappe in liste_tokards %}
<div class="article">
<h3>{{ptite_frappe.nom}} {{ptite_frappe.prenom}}</h3>
<p><a href="{% url 'interface' id_ienkli=petite_frappe.id_klient %}">Sélectionner cette petite frappe</a>
</div>
{% endfor %}
interface_du_klient.html
没有按照urls.py
的定义要求传递id_ienkli
的数字:
url(r'^interface_du_klient/(?P<id_ienkli>\d+)$', views.interface_du_klient, name='interface'),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.