Get the requested URL from django request

created at 07-17-2021 views: 9

django request Get the requested URL

  • request.get_host(): Get the request address
  • request.path: Get the requested path without parameters
  • request.path_info: Get the requested path without parameters
  • request.get_full_path(): Get complete parameters

Suppose the current URL is: http://www.stdworkflow.com/article/730.html?a=1

request.get_host()    # 

request.path          # article/730.html

request.get_full_path() article/730.html?a=1

Stupid way:

from urllib import parse

parse.urljoin('http://',request.get_host(),request.path)

# http://www.stdworkflow.com/article/730.html

Elegant approach

request.build_absolute_uri()

# http://www.stdworkflow.com/article/730.html
created at:07-17-2021
edited at: 07-17-2021: