# Method to access query string in Voila notebook

**URL:** <https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387>\
**Category:** General\
**Created:** [July 27, 2020, 11:37am UTC](https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387 "2020-07-27T11:37:54Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [February 9, 2022, 5:47am UTC](https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387/7 "2022-02-09T05:47:31Z")

</div>

**UPDATE** : This is how to use [the notebook that ConorMc posted above](https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387/4) with MyBinder to demonstrate the Voila-compatible way to access a query string **inside Voila**. (Bonus is that it demonstrates a Voila-compatible way of getting the full URL for when running in MyBinder, too.)

#### Step-by-step:

1. Launch a binder session with Voila installed and _slightly edited version_ of the notebook ConorMc posted above present by clicking [here](https://mybinder.org/v2/gh/fomightez/communication_voila/master?filepath=query-strings.ipynb).

2. When the session spins up and the demo notebook opens, you’ll notice the content of the notebook includes code setting ‘Kim’ as the username around the middle.

3. Launch the Voila version of this notebook by pressing ‘Voila’ button from the toolbar.

4. Voila will open and it will say `Hi Kim` towards the bottom of the content on the page.

5. Now to see the passing of the `username` query string in action, click on the blue link at the bottom that says ‘Link to myself as user Riley’. It should open another tab with Voila again.

6. Note that this new tab will include `?username=Riley` at the end of the URL. The content of the Voila page itself will look different now, too: **it will say ‘Hi Riley’ in place of ‘Hi Kim’** because this Voila instance has been passed a username via the URL.

You can see all the `envs` environment variables that the JupyterHub exposes to Voila by adding the following code to a cell in that demonstration notebook, saving the notebook, and launching Voila via the button on the toolbar.

```python
import os
envs = {k: v for k, v in os.environ.items()}
display (envs)

```

(Worked out from re-reading first link I posted in this thread and looking over the reference to the implementation therein, in particular, to [here](https://github.com/voila-dashboards/voila/blob/b003a7fc62023e5b4c8dab7dd64b94a920610c15/notebooks/query-strings.ipynb). I was too focused on the way I had been using javascript and missing some things. It was key to delete ‘localhost’ in the last cell with code in it in order to use [the notebook that ConorMc posted above](https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387/4) with MyBinder.)

---

_[View the full topic](https://discourse.jupyter.org/t/method-to-access-query-string-in-voila-notebook/5387)._
