2

I want to pass the model's id through the URL. I have created a path and view according but still I get NoReverseMatch at /url error.

Here's the code that I used in my project:

In template_name.html :

<a href="{% url 'url_name' model.id %}">

In view.py :

def view_name(request, id):

In urls.py:

path('url_name/<int:id>', view_name, name='url_name')
Javad
  • 2,033
  • 3
  • 13
  • 23
Manoj Kamble
  • 620
  • 1
  • 4
  • 21
  • Does this answer your question? [What is a NoReverseMatch error, and how do I fix it?](https://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do-i-fix-it) – Javad Apr 18 '22 at 06:56

2 Answers2

3

it is advisable to always add a trailing slash to your urls like so:

path('url_name/<int:id>/', view_name, name='url_name')

Hope it solves your problem.

Chymdy
  • 662
  • 4
  • 14
0

You can pass path param like this:

<a href={% url 'url_name' id=model.id %}>Click</a>
Hamid Rasti
  • 813
  • 1
  • 6
  • 16
  • Actually, I make comment on some stuff without putting model.id, that's why I am getting errors. After removing the comment section, It's working fine. – Manoj Kamble Apr 18 '22 at 07:05