0

I would like to get the COMPLETE URL using os.environ. I am rendering notebooks with voila and I would like to open url from a dashboard using parameters in the URL.

So far I have:

URL_BASE = os.environ.get('SCRIPT_NAME')
PARAMETERS = os.environ.get("QUERY_STRING")
print(f'{URL_BASE=}')
print(f'{PARAMETERS=}')

assuming this is the url:

https://flyingcar.org/john/voila/render/shared/users/j/john/learn_url.ipynb?redirects=2&name=john&dossier=SA123445#{whatever=no/f=5}

URL_BASE="flyingcar.org/john/voila/render/shared/users/j/john/learn_url.ipynb"
&
PARAMETERS="redirects=2&name=john&dossier=SA123445"

Having a look at the whole collection of vars in os.environ I dont see any that would include the whole url (including what is there after #) in order to parse that part as well as with parameters.

captured_values = parse_qs(PARAMETERS)
print('here parse_qs of query:',captured_values)
>>> here parse_qs of query: {'d': ['34'], 'f': ['56']}

Some ideas?

I tried to print all the os.environ variables with:

for k,v in os.environ.items():
    print(k,v)

but it nothing seems to contain what is beyond the # symbol in the URL Any ideas? Thanks

RELATED: Get current URL in Python

JFerro
  • 3,203
  • 7
  • 35
  • 88

1 Answers1

0

The fragment (#) part of the URI never leaves the user agent, so it can't be picked up by the python web server. See: https://datatracker.ietf.org/doc/html/rfc3986#page-24

... instead, the fragment identifier is separated from the rest of the URI prior to a dereference, and thus the identifying information within the fragment itself is dereferenced solely by the user agent, regardless of the URI scheme.

  • thanks @Mario. I read the specification, I could not find a real use case for "fragment" if it can not be recalled. – JFerro Jan 04 '22 at 13:50
  • 1
    @JFerro: In the browser it's used to scroll the page to an id on the page (like in the link in the answer). Also, the fragment can be read from JavaScript and is used for e.g. client-side routing. – Mario Buikhuizen Jan 04 '22 at 16:51