Open luanabeckerdaluz opened 12 months ago
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:
We create our own jinja2 environment here: https://github.com/jupyterhub/kubespawner/blob/6d9d9a36df3077b6ba22e4a94107ffe96fc2b18c/kubespawner/spawner.py#L2943. static_url and other helpers come from this jinja_env that is setup by JupyterHub (not kubespawner).
I'm not sure what exactly is the best way to move forward here.
Kubespawner renders a jinja2 template into another jinja2 template, is fix fix to ensure that static_url is parsed by the second jinja2 template rendering done by jupyterhub?
Kubespawner renders a jinja2 template into a string, that is then passed onto JupyterHub via options_form which expects a string. That is then rendered onto a jinja2 template.
I think the cleanest way perhaps is to add templating support into upstream JupyterHub for options forms, and move https://github.com/jupyterhub/kubespawner/pull/724 there.
Bug description
I am customizing jupyterhub templates by using images and css files stored in the jupyterhub static folder. When I need these images in the templates (page.html, login.html, spawner.html, etc.), I am accessing using the static_url() function with jinja. Nonetheless, I am not able to use this function or the functions url_for() and static() when calling it from inside kubespawner form.html. I also tried to access the STATIC_URL variable but the value was none.
Expected behaviour
The form.html file is used inside spawn.html in the object "{{spawner_options_form | safe}}". It is expected that some functions available by jinja when building jupyterhub templates also be available when building kubespawner form.html.
Actual behaviour
I think that Jinja is building the form html before insert this html in the spawner_options_form object of spawner.html. When building before, the function static_url() is undefined, while in the jupyterhub templates this function is defined. Below is shown the traceback when I tried to use this function in the html <img src="{{ static_url('images/cpu-ram.svg') }}>"
Your personal set up