M.E.
M.E.

Reputation: 5496

Bottle - Is it possible to retrieve URL without parameters?

I have an URL of the form:

http://www.foo.com/bar?arg1=x&arg2=y

If I do:

request.url

I get:

http://www.foo.com/bar?arg1=x&arg2=y

Is it possible to get just http://www.foo.com/bar?

Upvotes: 4

Views: 5432

Answers (3)

Yuvraj Jaiswal
Yuvraj Jaiswal

Reputation: 1723

Edit:

There is a way to do this via requests library

r.json()['headers']['Host']

I personally find the split function better.


You can use split function with ? as the delimiter to do this.

url = request.url.split("?")[0]

I'm not sure if this is the most effective/correct method though.

Upvotes: 2

M.E.
M.E.

Reputation: 5496

Looks like request.urlparts.path might be a way to do it.

Full documentation here.

Upvotes: 5

Garret
Garret

Reputation: 140

if you just want to remove the parameters to get base url do

url = url.split('?',1)[0]

this will split the url at the '?' and then give you base url

or even

url = url[:url.find('?')]

you can also use urlparse this is explained in the python docs at: https://docs.python.org/2/library/urlparse.html

Upvotes: 0

Related Questions