我正在开发一个简单的宠物商店应用程序
我几次遇到这个错误,我设法理解它并修复它,但在这种情况下。我不知道出了什么问题。一切对我来说似乎都很清楚。
它说我的 store.html 在 {% url world:brazil animal.id %} 的位置有一个错误,但我已经定义了命名空间。
Reverse for 'brazil' with arguments '('',)' and keyword arguments '{}' not found.
Error during template rendering
In template C:\djcode\mysite\pet\templates\store.html, error at line 5
Reverse for 'brazil' with arguments '('',)' and keyword arguments '{}' not found.
1 Sydney's Pet Store
2 {% if store %}
3 <ul>
4 {% for a in store %}
5 <li><a href ="{% url world:brazil animal.id %}">{{ a.name }}</li>
6 {% endfor %}
7
8 </ul>
9 {% endif %}
我的商店.html
Sydney's Pet Store
{% if store %}
<ul>
{% for a in store %}
<li><a href ="{% url world:brazil animal.id %}">{{ a.name }}</li>
{% endfor %}
</ul>
{% endif %}
我的观点.py
from pet.models import Store , Pet
from django.shortcuts import render_to_response ,get_object_or_404
def index(request):
store = Store.objects.all()
return render_to_response ('store.html',{'store':store})
def brazil(request , animal_id):
store = get_object_or_404(Store , Pet, pk=animal_id)
return render_to_response ('animal.html',{'store':store})
我的宠物应用 URLCONF:
from django.conf.urls import patterns,include , url
urlpatterns = patterns ('pet.views',
url(r'^$','index',name = 'index'),
url(r'^(?P<poll_id>\d+)/$','brazil',name ='brazil'),
)
我的主要URCONF:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.static import static
admin.autodiscover()
urlpatterns = patterns('',
url(r'^pet/',include('pet.urls' , namespace='world' )),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()