Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello everybody,
I would like to add the current date as a version of a css file in my django project to "bypass" the browser cache

What I have tried:

this seems work
Python
context = {
        'menu_list': menu_list,
        'date': datetime.datetime.now().strftime('%Y-%m-%d-%H:%M:%S'),

    }

    return render(request, 'index.html', context)


and I tried this on my base.html page
HTML
<link href="{% static 'css/custom.css' %}?v={{date}}" rel="stylesheet" type="text/css" id="app-style"/>


in the web view i see this

HTML
<link href="/static/css/custom.css?v=2023-01-19-09:43:21" rel="stylesheet" type="text/css" id="app-style">


but the browser cache problem is still the same
Posted
Updated 19-Jan-23 23:11pm
Comments
Richard Deeming 19-Jan-23 5:43am    
A colon in a query-string will need to be encoded as %3A - it would probably be easier to use the - character as the time separator:
'date': datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')


But if you never want the file cached, it would be better to have it returned with appropriate "no-cache" headers. How you configure that will depend on which web server you're using.
[no name] 19-Jan-23 8:30am    
nvm now its working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900