Importing reverse from django.urls

I am learning about testing and I wanted to know what reverse() does when testing for url availability. I tried Stack Overflow and django docs, but the explanation isn’t exactly clear. Eg:

class HomepageTests(SimpleTestCase):
    def test_url_available_by_name(self):
        response = self.client.get(reverse("home"))
        self.assertEqual(response.status_code, 200)

What does this do exactly?

Let’s work this through the docs. First, the docs for reverse say:

If you need to use something similar to the url template tag in your code, Django provides the following function:

So this leads us to the url tag, which starts out by saying:

Returns an absolute path reference (a URL without the domain name) matching a given view and optional parameters.

Following on that same page it goes on to provide an example as to what that function does.

So in this case, the reverse function is going to find your url path that is defined with name="home", and construct the url that would access it.

You can also see more examples and information about this in the Official Django tutorial, page 3.