Skip to content
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

How do I employ cache busting in a template? #673

Open
Dreamsorcerer opened this issue Jan 22, 2023 Discussed in #590 · 2 comments
Open

How do I employ cache busting in a template? #673

Dreamsorcerer opened this issue Jan 22, 2023 Discussed in #590 · 2 comments

Comments

@Dreamsorcerer
Copy link
Member

Discussed in #590

Originally posted by ugyballoons July 22, 2022
Hi,
I'm enjoying working with aiohttp and jinja2.
It's not clear to me how to employ cache busting. Please could someone help?
In the setup I have:

sub_app.add_routes(
    [
        web.static(
            "/static",
            Path(__file__).parent / "static",
            name="static",
            append_version=True,
        ),
    ]
)
sub_app["static_root_url"] = "/path-to/static"
env = aiohttp_jinja2.get_env(sub_app)
env.globals.update(
    zip=zip,
    url_for=web.Resource.url_for
)

and in the template I have:
<link rel="stylesheet" href="{{ url_for('static', filename='stylesheets/main.css') }}">

I feel that I shouldn't be passing url_for in the globals but if I don't, then jinja complains that there's no such function. Where am I going wrong?

@asvetlov
Copy link
Member

asvetlov commented Nov 29, 2024

Did you try built-in url() function?

<link rel="stylesheet" href="{{ url('static', filename='stylesheets/main.css') }}">

Also url_static() might help if app[aiohttp_jinja2.static_root_key] was set up properly.

@Dreamsorcerer
Copy link
Member Author

See the linked discussion. filename isn't documented is one problem.

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

No branches or pull requests

2 participants