错误指向{% url product %}
NoReverseMatch at /category/
Reverse for '' with arguments '()' and keyword arguments '{}' not found.
Request Method: GET
Request URL: http://127.0.0.1:8000/category/
Django Version: 1.4
Exception Type: NoReverseMatch
Exception Value:
Reverse for '' with arguments '()' and keyword arguments '{}' not found.
Exception Location: C:\Python27\lib\site-packages\django\template\defaulttags.py in render, line 424
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2
我的 HTML
<html>
<body>
<p> The list of items are </p>
{% for items in allobs %}
<li>{{items}}</li>
{% endfor %}
<p><a href="{% url product %}">Product list</a></p>
</body>
</html>
我的 VIEWS
from django.http import HttpResponse, Http404
from models import Category, Product
from datetime import datetime, timedelta, date, time
from django.shortcuts import render_to_response
def hello(request):
return HttpResponse("Hello World")
def category(request):
cat = Category.objects.all()
return render_to_response('category.html',{'allobs': cat})
def product(request):
pro = Product.objects.all()
return render_to_response('product.html',{'allobs':pro})
我的网址
from django.conf.urls.defaults import *
from django.contrib import admin
from website.views import hello, category, product
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^hello/$', hello),
url(r'^category/$', category),
(r'^tinymce/', include('tinymce.urls')),
url(r'^product/$', product),
)
if settings.DEBUG:
urlpatterns += patterns('django.views.static',
(r'images/(?P<path>.*)', 'serve', {'document_root': settings.MEDIA_ROOT}),
)
答案 0 :(得分:2)
如果产品是您的视图名称,则猜测{%url product%}应为{%url'产品'%}。
修改:同时使用视图'product.views.product'
的全名。