# Creating A Button For The Admin Page

**URL:** <https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147>\
**Category:** Templates & Frontend\
**Created:** [August 1, 2022, 5:26am UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147 "2022-08-01T05:26:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurbanoglu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gurbanoglu/32/8262_2.png) [@gurbanoglu](https://forum.djangoproject.com/u/gurbanoglu)\
**Post date:** [August 1, 2022, 5:26am UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/1 "2022-08-01T05:26:09Z")

</div>

Hi everyone.

I am trying to create a button that will take the user to the ‘[http://127.0.0.1:8000/admin/](http://127.0.0.1:8000/admin/)’ URL.

Inside `my django_project -> django_project -> urls.py` file I have the following:

```auto
urlpatterns = [
    path('admin/', admin.site.urls, name='admin'),
]

```

However, for the following button inside `django_project -> users -> templates -> users -> FacialLoginResult.html`, I am getting an error message saying " Reverse for ‘admin’ not found. ‘admin’ is not a valid view function or pattern name.":

```auto
    <a class="button" href="{% url 'admin' %}">Proceed</a>

```

How can I create a URL name for the ‘[http://127.0.0.1:8000/admin/](http://127.0.0.1:8000/admin/)’ page and use it in a button without seeing this error? What is the correct approach to take? Thank you.

---

<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:** [August 1, 2022, 12:44pm UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/2 "2022-08-01T12:44:51Z")

</div>

The path for `admin` is not a reference to a page or an included `urlpatterns` - it’s kinda a unique case. Anyway, the name parameter doesn’t seem to apply to anything here.

If you look at the source for the Django admin site, the root url has a name defined - `"index"` in the app named `admin`. Therefore, the url reference to it would be `'admin:index'`. (This also still works if you rename your admin site to a different name for security purposes. For example, if you define it as `path('xyzzy/', admin.site.urls)`, then `reverse('admin:index')` will return `'/xyzzy/'`.)

---

<div class="post-metadata">

**Author:** ![gurbanoglu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gurbanoglu/32/8262_2.png) [@gurbanoglu](https://forum.djangoproject.com/u/gurbanoglu)\
**Post date:** [August 1, 2022, 7:14pm UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/3 "2022-08-01T19:14:42Z")

</div>

Thank you very much Mr. Whitesell! The button is now working and directs the user to the admin’s page.

How do you think I can solve the following issue.

The following is a button that I have where I am trying to have the user click the button and open the link in another tab:

```auto
<button onclick="window.open("{% url 'profile' %}", '_blank'); return false;"
        class="btn btn-default" data-dismiss="modal">Go To The Profile Page</button>

```

`href="{% url 'profile' %}"` is how I normally format the URL name, but how would I format the URL name in this case as the first parameter of the `window.open()` function? The first parameter of the `window.open()` function expects a string indicating the URL.

---

<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:** [August 1, 2022, 8:13pm UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/4 "2022-08-01T20:13:19Z")

</div>

Why do you think the reference here would be different from any other location in the template?

---

<div class="post-metadata">

**Author:** ![gurbanoglu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gurbanoglu/32/8262_2.png) [@gurbanoglu](https://forum.djangoproject.com/u/gurbanoglu)\
**Post date:** [August 1, 2022, 9:51pm UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/5 "2022-08-01T21:51:07Z")

</div>

Because I get an error when trying it to do it the following way:

```auto
<button onclick="window.open("{% url 'profile' %}", '_blank'); return false;"
        class="btn btn-default" data-dismiss="modal">Go To The Profile Page</button>

```

The following is an image of the error:

 ![error](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/d/d9f7c2049191f90fa4bf7eaedb5852a30968d6f5.png)

Ultimately, the error is saying the following:

```auto
')' expected.javascript

```

How can I fix this 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:** [August 1, 2022, 10:00pm UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/6 "2022-08-01T22:00:46Z")

</div>

Ok, the issue here is that the quote before the `{` is closing the quotes in the `onclick` definition. So the problem here isn’t the use of the `url` tag, it’s the nested quotes within the JavaScript fragment.

It might be easiest to assign the url to a variable and reference that variable in the call to window.open.

---

<div class="post-metadata">

**Author:** ![gurbanoglu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gurbanoglu/32/8262_2.png) [@gurbanoglu](https://forum.djangoproject.com/u/gurbanoglu)\
**Post date:** [August 1, 2022, 11:07pm UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/7 "2022-08-01T23:07:58Z")

</div>

> [@KenWhitesell](#):
>
> It might be easiest to assign the url to a variable and reference that variable in the call to window.open.

You mean assign the URL (“{% url ‘profile’ %}”) to a JavaScript variable in the `<script></script>` section of the code?

---

<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:** [August 2, 2022, 12:46am UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/8 "2022-08-02T00:46:27Z")

</div>

Yes, that should allow you to get around this specific issue.

---

<div class="post-metadata">

**Author:** ![gurbanoglu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gurbanoglu/32/8262_2.png) [@gurbanoglu](https://forum.djangoproject.com/u/gurbanoglu)\
**Post date:** [August 2, 2022, 12:56am UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/9 "2022-08-02T00:56:41Z")

</div>

Good news Mr. Whitesell! I got the button to work and now the following link open in another tab `http://127.0.0.1:8000/profile/`.

The following is what I have:

```auto
<html>
<body>
<button onclick="window.open(profilePage, '_blank'); return false;"
                    class="btn btn-default" data-dismiss="modal">Go To The Profile Page</button>
</body>

<script>
    let profilePage = "{% url 'profile' %}";
</script>
</html>

```

My question is the following: Am I doing this the correct way? Would you do it a different way?

Thank you very much indeed Mr. Whitesell!

---

<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:** [August 2, 2022, 1:02am UTC](https://forum.djangoproject.com/t/creating-a-button-for-the-admin-page/15147/10 "2022-08-02T01:02:57Z")

</div>

I would say that you are doing it _one_ of the correct ways. I wouldn’t say this is the only way to do it - there are other ways of handling this that are just as valid.

Would I do it a different way? For me, it depends. There’s the possibility that other circumstances or conditions that may exist where I’d find it beneficial to choose a different approach. But that doesn’t make this “better” or “worse” than the other choices, just different.
