Categories
Python Answers

How to get the full or absolute URL (with domain) in Python Django?

Spread the love

To get the full or absolute URL (with domain) in Python Django, we can use the build_absolute_uri method.

For instance, we write

request.build_absolute_uri(reverse('view_name', args=(obj.pk, )))

to call request.build_absolute_uri with reverse('view_name', args=(obj.pk, ) to get the path of the view with reverse.

Then we call “request.build_absolute_uri` with the view path to return the full URL of the view.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *