'dynamic urls are routing to the same view Django
I'm trying to add two links. The first one leads from the dashboard to a profile page and the second one leads from the profile to a comment page for that profile. Instead of doing this, both links are leading to the same urlpattern(add_comment).
I understand it's happening because they have the same variables and it's only picking the first match but I don't know how to correct it.
In my path.py I have this:
urlpatterns = [
path('', views.home, name='home'),
path('dashboard.html', views.dashboard, name='dashboard'),
path('<int:person_id>', views.add_comment, name='add_comment'),
path('<int:person_id>', views.person_profile, name='person_profile'),
path('logout.html', views.logout_view, name='logout'),
and these are the templates:
THE DASHBOARD TEMPLATE TO LEAD TO THE PROFILE
{% extends "blog/base.html" %}
{% block content %}
{% for person in person_list %}
<a href="{% url 'account:person_profile' person.id %}">{{ person }}</a>
{% endfor %}
{% endblock content %}
THE PROFILE TEMPLATE TO LEAD TO THE ADD_COMMENT
{% extends "blog/base.html" %}
{% block content %}
<a href= "{% url 'account:add_comment' person.id %}">Add comment</a>
{% endblock content %}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
