1

In Flask, I want to send an URL in the URL as a parameter with all its parameters

Here is a working example http://graph.facebook.com/https://www.facebook.com/photo.php?fbid=717097101644637&set=a.456449604376056.98921.367116489976035&type=1&theater

I couldn't find a way, because the moment I cal something like this, the url doesn't go true.

@app.route('/<url>', methods=['GET'])

def show(url):
    """ do something with it """

Any idea how to do it?

Thank you

6
  • try to use this : @app.route('/<path:url>', methods=['GET']) Commented Dec 6, 2013 at 7:45
  • That works to the point that it will remove all the parameters from the URL. Commented Dec 6, 2013 at 7:59
  • are you trying to print the url on the page ? or you're trying to deal with its data "json" ? Commented Dec 6, 2013 at 8:38
  • Trying to use the url, I don't care about the json. I want to achieve the same functionality, not get the same data. Commented Dec 6, 2013 at 8:58
  • 2
    The best I could come up to this moment is url = request.url.replace(request.url_root,'') for the URL and @app.route('/<path:url>', methods=['GET']) for the app.route. Commented Dec 6, 2013 at 15:40

2 Answers 2

1

If you look at what Facebook returns for that URL:

{
   "id": "https://www.facebook.com/photo.php",
   "shares": 377224,
   "comments": 2
}

you will note that the query string params are being consumed by graph.facebook.com - they are not treated as part of the URL that is being submitted as a search param. If you want to be able to get the whole URL including query string arguments, you will need to URL-encode the query string your.url/https://www.facebook.com/photo.php%3Ffbid=717097101644637%26set=a.456449604376056.98921.367116489976035%26type=1%26theater

Sign up to request clarification or add additional context in comments.

1 Comment

I gave Facebook as the closest example. I know they don't do exactly what I wanted. Unfortunately I can't URL encode the whole string, because if you will paste the link into your browsers (at least in Safari) it will do exactly what happened there.
1

Unfortunately, I can't control if the URL is URL-encoded so the best thing I came along is this.

_url = request.url.replace(request.url_root,'')
url = urllib.unquote(_url)

Maybe it will help somebody.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.