Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get getting base_url in django template

Tags:

python

django

Given a website, how would you get the HOST of that in a django template, without passing that var from the view?

http://google.com/hello --> {{ BASE_URL }} ==> 'http://google.com'
like image 578
David542 Avatar asked Feb 19 '15 21:02

David542


1 Answers

This has been answered extensively in the following post

There are several ways of doing it:

  1. As david542 described **
  2. Using {{ request.get_host() }} in your template **
  3. Using the contrib.sites framework

** Please note these can be spoofed

like image 50
Elwin Avatar answered Sep 27 '22 00:09

Elwin