Django中的自定义HTTP头 [英] Custom HTTP Header in Django

查看:561
本文介绍了Django中的自定义HTTP头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

继续使用:

  request.META.get('HTTP_ {your uppercased header name}')

注意,在Django中,您使用下划线(而不是破折号)在大写字母中写入头文件名,但在客户端您必须使用破折号而不是下划线来编写它(出于安全原因,生产Web服务器将从其中删除带有下划线的自定义标题)。



所以,一个自定义的追随者 My-Custom-Header 被访问 request.META [ 'HTTP_MY_CUSTOM_HEADER']


I use a custom http header for URL signature just called "sign", how to get such custom HTTP header value in Django?

解决方案

Go ahead and use:

request.META.get('HTTP_{your uppercased header name}')

Note in Django you write the header name in capitals with underscores instead of dashes, but in the request on the client you must write it using dashes instead of underscores (production web servers will strip out custom headers with underscores in them for security reasons).

So, a custom herader My-Custom-Header is accessed request.META['HTTP_MY_CUSTOM_HEADER']

这篇关于Django中的自定义HTTP头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆