Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current URL in Python

Tags:

How would i get the current URL with Python,

I need to grab the current URL so i can check it for query strings e.g

requested_url = "URL_HERE"  url = urlparse(requested_url)  if url[4]:     params = dict([part.split('=') for part in url[4].split('&')]) 

also this is running in Google App Engine

like image 725
Alex Avatar asked May 04 '10 10:05

Alex


2 Answers

Try this:

self.request.url 

Also, if you just need the querystring, this will work:

self.request.query_string 

And, lastly, if you know the querystring variable that you're looking for, you can do this:

self.request.get("name-of-querystring-variable") 
like image 134
jamesaharvey Avatar answered Oct 15 '22 04:10

jamesaharvey


For anybody finding this via google,

i figured it out,

you can get the query strings on your current request using:

url_get = self.request.GET 

which is a UnicodeMultiDict of your query strings!

like image 37
Alex Avatar answered Oct 15 '22 06:10

Alex