[英]How to set Content-Type header for 304 http response code?
So I am using few decorators from Django to enable caching on my API: 因此,我使用了一些来自Django的装饰器来启用API上的缓存:
@require_GET
@cache_page(100)
@cache_control(max_age=100, s_maxage=100)
@csrf_exempt
def my_api(request):
The problem is, 304 Not Modified response is coming back with text/html Content-Type header. 问题是,text / html Content-Type标头返回了304 Not Modified响应。 My API normally returns application/json Content-Type header and I would like to be consistent. 我的API通常返回application / json Content-Type标头,我希望保持一致。 Is there a way to tell Django what content type to return with 304 response code? 有没有办法告诉Django 304响应码返回哪种内容类型?
The problem is here https://github.com/django/django/blob/master/django/http/response.py#L411 问题在这里https://github.com/django/django/blob/master/django/http/response.py#L411
Write a decorator to add the mimetype again 编写装饰器以再次添加mimetype
def RestoreMime(fn):
def Wrapper(*args, **kwds):
response = fn(*args, **kwds)
response['Content-type'] = your_mime_type
return response
return Wrapper
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.