etag&last_modified&condition& django.middleware.http.ConditionalGetMiddleware
Posted 本站大佬
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了etag&last_modified&condition& django.middleware.http.ConditionalGetMiddleware相关的知识,希望对你有一定的参考价值。
views.py
from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponseNotFound
from django.shortcuts import render
# Create your views here.
from django.views.decorators.http import etag, last_modified, condition
from syboy1.models import symodel
def etag_funcview(request):
etag_head = hash(str(symodel.objects.latest('pubdate').name))
print(etag_head)
return str(etag_head)
def last_modifiedview(request):
return symodel.objects.latest('pubdate').pubdate
# @condition(etag_func=etag_funcview,last_modified_func=last_modifiedview)
# @last_modified(last_modifiedview)
# @etag(etag_funcview)
def aa1(request):
name = symodel.objects.latest('pubdate').name
print(name)
return HttpResponse(name)
def aa(request):
return HttpResponseNotFound("None")
def pa(request):
return HttpResponse('pa')
setting.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
]
USE_ETAGS=True
以上是关于etag&last_modified&condition& django.middleware.http.ConditionalGetMiddleware的主要内容,如果未能解决你的问题,请参考以下文章
如何在 oracle 中使用空值检查 last_modified 日期