Skip to content

yarl update broke static file urls in templates #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
14droplets opened this issue Sep 12, 2023 · 4 comments · Fixed by #479
Closed

yarl update broke static file urls in templates #478

14droplets opened this issue Sep 12, 2023 · 4 comments · Fixed by #479

Comments

@14droplets
Copy link
Contributor

With yarl version 1.9.2 static files urls with url_for(filename="") as used, for example, here:

static_path = request.app.router[STATIC_ROUTE_NAME].url_for(filename="")
are no longer works correctly. Produced URL no longer contains terminating slash to be concatenated with filename in template code like it is done here:
<link rel="stylesheet" href="{{ static_path }}css/debugger.css" type="text/css">

I traced issue to this line in yarl: https://github.com/aio-libs/yarl/blob/1f94e1a7833a27203d63f8618d01d4d4fa2d3520/yarl/_url.py#L719. With segment as empty string - main loop breaks immediately.

Issue is observed with yarl versions 1.9.2 and 1.9.1 and disappears with yarl version 1.8.2.

I can rewrite templates using url_for instead of {{ static_path }}css/debugger.css like syntax and provide a pull request. Is it acceptable fix? Should I do it?

@Dreamsorcerer
Copy link
Member

aiohttp-jinja2 has static(): https://aiohttp-jinja2.readthedocs.io/en/stable/#default-globals

So, if you can update to that, that would be perfect.

@14droplets
Copy link
Contributor Author

Thank you, interesting feature. But using that would require to mess with app['static_root_url'] which may be used by user.
I will try to do something like this but autonomous

@Dreamsorcerer
Copy link
Member

Oh, yes, we can't use that until #71 is done.
Will need to stick with a hack for now.

@14droplets
Copy link
Contributor Author

Hacky hack goes brrr. As hacky as I could, but without ANY additional pollution to globals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants