NoReverseMatch at / error

时间:2017-03-18 22:32:29

标签: django django-templates django-views

我知道互联网上有很多这个问题的解决方案,但我会做的就是收到这样的错误 -

Reverse for 'get_category' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['category/(?P<alias>[^/]+)']. 

模板

<a href="{% url 'get_category' category.alias %}">

视图

def products(request, alias):
    try:
        product = Items.objects.get(alias=alias)
        title = product.name
    except:
        raise Http404("Объект не найден")

    context = {

    }

    return render(request, 'product/product.html', context)


def get_category(request, alias):
    try:
        category = Category.objects.get(alias=alias)
        products = Items.objects.filter(category=category)
    except:
        raise Http404('Объекты не найден')
    context = {
        'products': products,
        'category': category,
    }
    return render(request, 'popular/popular.html', context)

网址

url(r'^$', views.popular, name='popular'),
url(r'^products/(?P<alias>[^/]+)', views.products, name='product'),
url(r'^category/(?P<alias>[^/]+)', views.get_category, name='get_category'),

0 个答案:

没有答案