In my home page i have a profile pic on cha开发者_开发问答nging the profile pic i update the DB and redirevt the page to /home . But now when i redirect the old picture remains the same till refresh button is hit.Ami doing anything wrong here
This is in the python code
return HttpResponseRedirect('/home')
This is in the base html page in /home
<img src="{{photo}}" ></img>
Maybe the profile picture is cached by the browser. There are multiple ways to avoid it:
disable caching for the by changing the response headers for it. This is a bad idea for production because the picture would never be cached, so every page-request would fetch the picture, which massively increases the traffic
change the filename of the photo when it is update. You could i.e. use a hash of the content or something like
SHA1(userid + timestamp of upload)
use a HTTP ETag in the response header of the picture
There's a trick I read that consists in writing something like:
<img src="{{photo}}?version={{version}}"></img>
Where version is a new version number that you increase when your file is updated (you could alternatively use {{photo.file}}
and {{photo.version}}
).
This way the URL will be different and the browser will not used the cached version.
精彩评论