django request Get the requested URL
request.get_host()
: Get the request addressrequest.path
: Get the requested path without parametersrequest.path_info
: Get the requested path without parametersrequest.get_full_path()
: Get complete parametersSuppose 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