Reputation: 202
I have an anchor tag in an html template as :
<a href="{% url 'each_product' pk=product.id %}"> View</a>
In urls.py i have set up the url path as follow for this:
path("each_product/<int:pk>/", views.each_product, name="each_product")
And in view i have defined the function each_product as:
def each_product(request, pk):
return render(request, "store/view_each_product.html")
I have template named as view_each_product.html. Whenever i try to click view tag , it says
"Reverse for 'each_product' with no arguments not found. 1 pattern(s) tried: ['each_product/(?P[0-9]+)/$']"
But , when i try to render other templates such as home page , or any other than this ! It doesn't show error.
Upvotes: 0
Views: 20
Reputation: 3392
you need to pass the context also
def each_product(request, pk):
product = get_object_or_404(Product, pk=pk)
return render(request, "store/view_each_product.html", {"product":product})
Upvotes: 1