Как я могу решить это?
Как добавить заголовок кэша в HttpResponse?
Теперь файл не кэшируется. Этот модуль необходим для поиска и возврата фотографий или картинок.
Просто нужно кешировать файл на клиенте в браузере.
мои взгляды:
def q(request, slug, name):
arr = {
'png': 'image/png',
'jpg': 'image/jpeg',
'gif': 'image/gif',
}
current_time = datetime.datetime.utcnow()
image_data = open(path, 'rb').read()
response = HttpResponse(image_data, content_type = arr[extension])
last_modified = current_time - datetime.timedelta(days=1)
response['Last-Modified'] = last_modified.strftime('%a, %d %b %Y %H:%M:%S GMT')
response['Expires'] = current_time + datetime.timedelta(days=30)
response['Cache-Control'] = 'public, max-age=315360000'
response['Date'] = current_time
response['Cache-Control'] = 'no-cache'
return response
Заголовки ответа:
Cache-Control: no-cache, max-age=900
Content-Length: 767365
Content-Type: image/gif
Date: 2019-05-06 20:21:25.134589
Expires: 2019-06-05 20:21:25.134589
Last-Modified: Sun, 05 May 2019 20:21:25 GMT
Server: WSGIServer/0.2 CPython/3.7.3
X-Frame-Options: SAMEORIGIN
Заголовки запроса:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Cache-Control: max-age=0
Connection: keep-alive
Host: localhost:8088
If-Modified-Since: Sun, 05 May 2019 20:21:14 GMT
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36