I want to pass the model's id through the URL. I have created a path and view according. Still, I am getting error as ' NoReverseMatch at /url '.
Here's the code that I used in Project.
In Template :
<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')
CodePudding user response:
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.
CodePudding user response:
You can pass path param like this:
<a href={% url 'url_name' id=model.id %}>Click</a>