开发者

Django: check content_type of a request?

开发者 https://www.devze.com 2023-02-22 05:18 出处:网络
I\'d like to know if a request is HTML, CSS, image etc (in middleware). I\'ve tried: print request.META[\'CONTENT_TYPE\']

I'd like to know if a request is HTML, CSS, image etc (in middleware).

I've tried:

print request.META['CONTENT_TYPE'] 

but that gives me:

text/plain
开发者_开发知识库

for everything, CSS and images alike.

Any advice?

Thanks!


I think you need to only be serving text based things through Django. Static media should be served through your production server. See this part of the docs

Secondly, you probably want to be checking the response, not the request.


Assuming you're using process_response, as Issac mentioned, you need to be looking at response.

0

精彩评论

暂无评论...
验证码 换一张
取 消