views:

297

answers:

4

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

A: 

Try this

import os
url = os.environ['HTTP_HOST']
Arty
this appears to ignore any query strings as it's only grabbing the host URL:ParseResult(scheme='localhost', netloc='', path='8080', params='', query='', fragment='')
Alex
+9  A: 

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")
jamesaharvey
self.request.query_string works great thanks
Alex
A: 

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!

Alex
Yes, in general you want to use the tools provided by your framework and not manually parse URLs; this is a solved problem.
Wooble
A: 

How to retrive querry string

rikymartin