# Reverse admin urls

**URL:** https://forum.djangoproject.com/t/reverse-admin-urls/41535
**Category:** The Admin
**Created:** [June 22, 2025, 2:57pm UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535 "2025-06-22T14:57:42Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![moanos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/moanos/32/28994_2.png) [@moanos](https://forum.djangoproject.com/u/moanos)
#### Post date: [June 22, 2025, 2:57pm UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535/1 "2025-06-22T14:57:42Z")

</div>

I’m currently trying to add a link to an object in the admin interface in a view.  
The [Documentation on reversing admin URLs](https://docs.djangoproject.com/en/5.2/ref/contrib/admin/#reversing-admin-urls) says the following should work

```auto
<a href="{% url opts|admin_urlname:'add' %}">Add user</a>

```

in my case this would be

```auto
<a href="{% url org|admin_urlname:'change' %}" org.id>Change Rescue Orgnaization</a>

```

However I get the following error

```auto
'RescueOrganization' object has no attribute 'app_label'

```

I know that I need an app label

> The `opts` variable can be any object which has an `app_label` and `model_name` attributes and is usually supplied by the admin views for the current model.

However I don’t understand why RescueOrganizations has no app label? It’s in my normal models.py and just as a sanity check I had a look in the DB and the table is called  
`fellchensammlung_rescueorganization`.

I also tried setting the app label, without any effect.

Any idea what could cause this?

If you want to check out the source here are some links (but I’d also be happy to provide the relevant snippets)

- [views.py](https://codeberg.org/moanos/notfellchen/src/commit/b91a17e950d5f457f85fedbdd66507574811acf8/src/fellchensammlung/views.py#L685)
- other links in a response, as I’m a new user I can only post two links 😀

Other things I tried are reversing it in the views.py like this

```auto
change_url = reverse("admin:fellchensammlung_rescue_org_change", args=(org.id,), current_app="fellchensammlung")

```

but that failed with

```auto
Reverse for 'fellchensammlung_rescue_org_change' not found. 'fellchensammlung_rescue_org_change' is not a valid view function or pattern name.

```

Thanks for taking your time to read it!

---

<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: [June 22, 2025, 3:48pm UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535/2 "2025-06-22T15:48:41Z")

</div>

Welcome @moanos !

While I can’t verify everything here, I do see that:

> [@moanos](#):
>
> `<a href="{% url org|admin_urlname:'change' %}" org.id>Change Rescue Orgnaization</a>`

is constructed incorrectly.

The `org.id` needs to be part of the url tag to pass as a parameter to the ‘change’ url.

Notice the difference in the location of the parameter between what you have above and the sample in the docs:  
`<a href="{% url opts|admin_urlname:'delete' user.pk %}">Delete this user</a>`

Also, the models themselves do not have `app_label` and `model_name` attributes. They’re exposed in the `_meta` attribute of the model. This means you should use something like `{% url org._meta|admin_urlname:'change' ...`

---

<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: [June 22, 2025, 3:52pm UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535/3 "2025-06-22T15:52:19Z")

</div>

Also, you do not have a model named `rescue_org`. For the purpose of the `reverse` function, I would expect you to need to use `'fellchensammlung_rescueorganization_change'`

---

<div class="post-metadata">

### Author: ![moanos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/moanos/32/28994_2.png) [@moanos](https://forum.djangoproject.com/u/moanos)
#### Post date: [June 22, 2025, 4:10pm UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535/4 "2025-06-22T16:10:06Z")

</div>

> [@KenWhitesell](#):
>
> The `org.id` needs to be part of the url tag to pass as a parameter to the ‘change’ url.

Oh yes. Sorry I seem to have pasted this wrong. this is what I actually have in the code

```auto
<a href="{% url org|admin_urlname:'change' org.pk %}">Admin interface</a>

```

would that be correct on it’s own?

---

<div class="post-metadata">

### Author: ![moanos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/moanos/32/28994_2.png) [@moanos](https://forum.djangoproject.com/u/moanos)
#### Post date: [June 22, 2025, 6:48pm UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535/5 "2025-06-22T18:48:48Z")

</div>

> [@KenWhitesell](#):
>
> Also, you do not have a model named `rescue_org`. For the purpose of the `reverse` function, I would expect you to need to use `'fellchensammlung_rescueorganization_change'`

You are absolutely right, however I also tried this and it results in the same error

```auto
NoReverseMatch at /tierschutzorganisationen/2900/

Reverse for 'fellchensammlung_rescueorganization_change' not found. 'fellchensammlung_rescueorganization_change' is not a valid view function or pattern name.

```

Sorry for the mess, I tried so many things and pasted the wrong attempts in my initial post.

---

<div class="post-metadata">

### Author: ![moanos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/moanos/32/28994_2.png) [@moanos](https://forum.djangoproject.com/u/moanos)
#### Post date: [June 23, 2025, 10:29am UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535/6 "2025-06-23T10:29:35Z")

</div>

Thank you again, I got your response now after sleeping over it!

In the template I now have

```auto
# detail-rescue-org.html
<a href="{% url org_meta|admin_urlname:'change' org.pk %}"><i class="fa-solid fa-tools fa-fw"></i> Admin interface</a>

```

This is a slight difference to what you proposed as I can’t access `._meta` in a template (`Variables and attributes may not begin with underscores: 'org._meta'`)

I therefore added the following to my context:

```auto
#views,py
org = RescueOrganization.objects.get(pk=rescue_organization_id)
    org_meta = org._meta
    return render(request, template,
                  context={"org": org, "org_meta": org_meta})

```

Thanks again for your help @KenWhitesell !

---

<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: [June 23, 2025, 11:03am UTC](https://forum.djangoproject.com/t/reverse-admin-urls/41535/7 "2025-06-23T11:03:45Z")

</div>

> [@moanos](#):
>
> You are absolutely right, however I also tried this and it results in the same error
> 
> ```auto
> NoReverseMatch at /tierschutzorganisationen/2900/
> 
> Reverse for 'fellchensammlung_rescueorganization_change' not found. 'fellchensammlung_rescueorganization_change
> 
> ```

If you are still interested in resolving this one, please post your `reverse` function call code.
