0

错误指向{% 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>

我的观点

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}),       
    )
4

1 回答 1

2

如果 product 是您的视图名称,猜猜 {% url product %} 应该是 {% url 'product' %}。

编辑:也使用视图的全名'product.views.product'

于 2013-06-20T09:57:55.803 回答