Creating A Button For The Admin Page

Hi everyone.

I am trying to create a button that will take the user to the ‘’ URL.

Inside my django_project -> django_project -> file I have the following:

urlpatterns = [
    path('admin/',, 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.":

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

How can I create a URL name for the ‘’ page and use it in a button without seeing this error? What is the correct approach to take? Thank you.

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/',, then reverse('admin:index') will return '/xyzzy/'.)

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:

<button onclick=""{% 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 function? The first parameter of the function expects a string indicating the URL.

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

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

<button onclick=""{% 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:

Ultimately, the error is saying the following:

')' expected.javascript

How can I fix this issue?

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

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

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

Good news Mr. Whitesell! I got the button to work and now the following link open in another tab

The following is what I have:

<button onclick=", '_blank'); return false;"
                    class="btn btn-default" data-dismiss="modal">Go To The Profile Page</button>

    let profilePage = "{% url 'profile' %}";

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!

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.