Created
October 30, 2024 17:04
-
-
Save grizmio/651ec466ac13e02a44cc6ba37c402b19 to your computer and use it in GitHub Desktop.
monkeypatch decorating django handle_simple tag (static tag)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.templatetags.static import StaticNode | |
def patch_static_tag(unique_per_deploy: str): | |
def handle_simple_wrapper(func): | |
def wrapper_func(cls, path): | |
resolved_static_path = func(path) | |
if resolved_static_path.endswith('.js') or resolved_static_path.endswith('.css'): | |
resolved_static_path += f'?u={unique_per_deploy}' | |
return resolved_static_path | |
return classmethod(wrapper_func) | |
StaticNode.handle_simple = handle_simple_wrapper(StaticNode.handle_simple) | |
# call it from settings.py | |
patch_static_tag('11111111') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment