本文整理汇总了Python中django.http.HttpRequest.META['HTTP_ACCEPT']方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.META['HTTP_ACCEPT']方法的具体用法?Python HttpRequest.META['HTTP_ACCEPT']怎么用?Python HttpRequest.META['HTTP_ACCEPT']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.META['HTTP_ACCEPT']方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resolver
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META['HTTP_ACCEPT'] [as 别名]
def test_resolver(self):
request = HttpRequest()
request.method = 'GET'
request.META['HTTP_ACCEPT'] = '*/*'
response = self.b(request)
self.assertEqual(response.content, '[{"id": 1}, {"id": 2}]')
示例2: test_options
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META['HTTP_ACCEPT'] [as 别名]
def test_options(self):
request = HttpRequest()
request.method = 'OPTIONS'
request.META['HTTP_ACCEPT'] = 'application/json'
response = self.a(request)
self.assertEqual(response['Allow'], 'OPTIONS')
示例3: test_json_includes_allow_header
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META['HTTP_ACCEPT'] [as 别名]
def test_json_includes_allow_header(self):
class TestAllowActionResource(Resource):
def get_actions(self):
return { 'delete': Action(method='DELETE', attributes=None) }
request = HttpRequest()
request.META['HTTP_ACCEPT'] = 'application/json'
response = TestAllowActionResource().get(request)
self.assertEqual(response['Allow'], 'HEAD, GET, DELETE')
示例4: test_mimetype
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META['HTTP_ACCEPT'] [as 别名]
def test_mimetype(self):
request = HttpRequest()
request.method = 'GET'
request.META['HTTP_ACCEPT'] = '*/*'
self.b(request)
self.assertEqual(request.accepttype, 'application/json')
request = HttpRequest()
request.method = 'PUT'
request.META['CONTENT_TYPE'] = 'application/json; charset=utf-8'
request._raw_post_data = '{"name": "Sally Doe", "age": null}'
self.b(request)
self.assertEqual(request.contenttype, 'application/json')
self.assertTrue(hasattr(request, 'PUT'))
示例5: test_webp_support_true
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META['HTTP_ACCEPT'] [as 别名]
def test_webp_support_true(self):
request = HttpRequest()
request.META['HTTP_ACCEPT'] =\
'text/html,application/xhtml+xml,application/xml;' \
'q=0.9,image/webp,*/*;q=0.8'
assert webp_support(request) == {'webp_compatible': True}
示例6: test_webp_support_false
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import META['HTTP_ACCEPT'] [as 别名]
def test_webp_support_false(self):
request = HttpRequest()
request.META['HTTP_ACCEPT'] =\
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
assert webp_support(request) == {'webp_compatible': False}