# what are the conditions in which we get NoReverseMatch error

**URL:** <https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913>\
**Category:** Templates & Frontend\
**Created:** [March 6, 2021, 5:01am UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913 "2021-03-06T05:01:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karki1234](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/karki1234/32/3308_2.png) [@Karki1234](https://forum.djangoproject.com/u/Karki1234)\
**Post date:** [March 6, 2021, 5:01am UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913/1 "2021-03-06T05:01:11Z")

</div>

what are the conditions in which we get NoReverseMatch error:

i get this error many times in my project. I want to know why and how this error is raised and how to solve this problems.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 6, 2021, 5:57am UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913/2 "2021-03-06T05:57:36Z")

</div>

It’s caused by trying to reverse a url name that isn’t defined. It’s typically thrown by a call to reverse or reverse\_lazy. It’s resolved by ensuring all calls to reverse reference a name defined for a url.

---

<div class="post-metadata">

**Author:** ![AmplifiedAnima](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/amplifiedanima/32/10227_2.png) [@AmplifiedAnima](https://forum.djangoproject.com/u/AmplifiedAnima)\
**Post date:** [September 27, 2022, 12:10pm UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913/3 "2022-09-27T12:10:15Z")

</div>

Sir, for example if I have

> {% include ‘homemain.html’%}  
> {% block content %}  
> {%for profil in profilki%}
> 
> ```
> <h3>  
> <a href="{%url 'profilepage' profilepage.id%}"> {{profil}} - profiles </a>
> </h3>
> 
> ```
> 
> {% endfor %} {% endblock content %}

> urls.py  
> path (‘profilepage/str:pk/’,views.profilepage,name=“profilepage”),  
> path (‘profilki/’, views.profilki,name=“profilki”),

and passing [http://127.0.0.1:8000/profilepage/1/](http://127.0.0.1:8000/profilepage/1/) returns me the page Im trying to access, where is the issue ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 27, 2022, 12:14pm UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913/4 "2022-09-27T12:14:12Z")

</div>

You have:

> [@AmplifiedAnima](#):
>
> `<a href="{%url 'profilepage' profilepage.id%}">`

This will create an error if any of the following are true:

- You do not have an object named `profilepage` in your context.
- The `profilepage` object does not have an attribute named `id`
- The `profilepage.id` entity does not provide a value.

---

<div class="post-metadata">

**Author:** ![AmplifiedAnima](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/amplifiedanima/32/10227_2.png) [@AmplifiedAnima](https://forum.djangoproject.com/u/AmplifiedAnima)\
**Post date:** [September 27, 2022, 12:52pm UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913/5 "2022-09-27T12:52:44Z")

</div>

```auto
def profilki(request):
     
  profilki = profile.objects.all()
     
     context = {'profilki':profilki }
 
     return render(request,'base/profilki.html',context)
 
 
 
 def profilepage(request,pk):
     user = Trainingvalue.objects.get(id=pk)
     trainingplan = Trainingvalue.objects.all()
     profilepage= profile.objects.get(id=pk)
     user_training= Trainingvalue.objects.filter(user=profilepage.user)
     context ={'user_training':user_training,'user':user,'profilepage':profilepage,
     'trainingplan':trainingplan,}
 
     return render(request, 'base/profilepage.html' , context)

url : path ('profilepage/<str:pk>/',views.profilepage, name="profilepage")

```

profilepage in context V  
profile page has an attribute id V  
profilepage.id entity does not provide value - yet i can access it through the borwser…

so technically this should work:

```
<a href=" {%url 'profilepage' profilepage.id %} "> profile </a>

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 27, 2022, 2:02pm UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913/6 "2022-09-27T14:02:57Z")

</div>

Side note: When posting code here, please enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

Please edit your post. Also clarify which of the two views posted is causing the error to be thrown and which template file that `<a ..` tag is in.

---

<div class="post-metadata">

**Author:** ![AmplifiedAnima](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/amplifiedanima/32/10227_2.png) [@AmplifiedAnima](https://forum.djangoproject.com/u/AmplifiedAnima)\
**Post date:** [September 27, 2022, 2:22pm UTC](https://forum.djangoproject.com/t/what-are-the-conditions-in-which-we-get-noreversematch-error/6913/7 "2022-09-27T14:22:19Z")

</div>

Sir I’ve resolved issue by putting it this way in a template :

```auto

 
 {% include 'homemain.html'%}
 
 {% block content %}
 
 {%for profil in profilki%}
 
 <div>
   
 <h3>{{profil}} -<a href="{%url 'profilepage' profil.id %}">profile </a></h3>
 
     
 </div>
 
 {% endfor %}
 
{% endblock content %}

```

Thank you for your help, it made me think
