我是Django的新手,我在页面的网址“DetailLivre.html
”中遇到了问题:
使用URLconf
中定义的Ilhem.urls
,Django按此顺序尝试了这些网址格式:
^Bibliotheque/ ^$ [name='index']
^Bibliotheque/ ^(?P<livre_id>[0-9]+)/$ [name='DetailLivre']
^admin/
当前网址Bibliotheque/BOOK1/
与其中任何网址都不匹配。*
我正在使用:Python 2.7.6
,django 1.8.5
你可以帮忙吗?
的index.html:
<h1>La liste des Livres </h1>
{% block content %}
{% block theme %}
{% load bootstrap_themes %}
{% bootstrap_styles theme='default' type='min.css' %}
{% bootstrap_styles theme='cosmo' type='css' %}
{% bootstrap_styles theme='united' type='less' %}
{% bootstrap_script use_min=True %}
{% endblock theme %}
{% if BookList%}
<div class="container-fluid">
<div class="row">
<ul>
{% for livre in BookList %}
<li><a href="/Bibliotheque/{{ livre.Titre }}/">{{ livre.Titre }}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% else %}
<p>Pas de Livres.</p>
{% endif %}
{% endblock %}
DetailLivre.html
<h1>{{ Auteur }}</h1>
<label for="Nom">{{ Auteur.Nom }}</label><br />
<label for="Prenom">{{ Auteur.Prenom }}</label><br />
<label for="dateNaissance">{{ Auteur.dateNaissance }}</label><br />
<label for="Lieu_de_naissance">{{ Auteur.Lieu_de_naissance }}</label><br />
<label for="Specialite">{{ Auteur.Specialite }}</label>
Views.py
from django.shortcuts import render
from django.template import RequestContext, loader
from django.http import HttpResponse
from django.template import RequestContext, loader
from django.shortcuts import get_object_or_404, render
from .models import Livre, Auteur
def index(request):
BookList = Livre.objects.all()
template = loader.get_template('Bibliotheque/index.html')
context = RequestContext(request, {
'BookList': BookList,
})
return HttpResponse(template.render(context))
def DetailLivre(request, livre_id):
livre = Livre.objects.get(pk=livre_id)
return render(request, 'Bibliotheque/DetailLivre.html', {'livre.Titre': livre.Titre})
url.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^(?P<livre_id>[0-9]+)/$', views.DetailLivre, name='DetailLivre'),
]
答案 0 :(得分:0)
您缺少BOOK前缀BOOK(?P<livre_id>[-\d]+)