How can I get the absolute URL with domain in Django

0 votes
How can I get the full/absolute URL (e.g. https://example.com/some/path) in Django without the Sites module? I shouldn't need to query my DB to snag the URL!
Aug 6, 2020 in Python by kartik
• 37,510 points
3,306 views

1 answer to this question.

0 votes

Hello @kartik,

Use handy request.build_absolute_uri() method on request, pass it the relative url and it'll give you full one.

By default, the absolute URL for request.get_full_path() is returned, but you can pass it a relative URL as the first argument to convert it to an absolute URL.

Hope it helps!!
Thank you!

answered Aug 6, 2020 by Niroj
• 82,720 points

Related Questions In Python

0 votes
1 answer

How can I get the username of the logged-in user in Django?

Hello @kartik, You can use the request object ...READ MORE

answered Jul 29, 2020 in Python by Niroj
• 82,720 points
4,396 views
0 votes
2 answers

How can I get the count of a list in Python?

n=[1,2,3,4,5,6,7,8,9] print(len(n)) =9 READ MORE

answered Dec 10, 2020 in Python by anonymous
405 views
0 votes
1 answer

How can I lookup hostname using the IP address with a timeout in Python?

Good question. I actually was stuck with ...READ MORE

answered Feb 6, 2019 in Python by Nymeria
• 3,520 points
1,073 views
0 votes
0 answers

How can i get the content in the JSON format while making the GET requests in python?

While making POST requests how can we ...READ MORE

Jun 6, 2019 in Python by Waseem
• 4,540 points
152 views
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,720 points
774 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,720 points
316 views
0 votes
1 answer

How can I get the domain name of my site within a Django template?

Hello kartik, The variation of the context processor ...READ MORE

answered Apr 23, 2020 in Python by Niroj
• 82,720 points
3,406 views
0 votes
1 answer

How can I get all the request headers in Django?

Hello @kartik,  You can use request.headers to access the HTTP ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,720 points
3,165 views