跳转到主要内容

一个检查浏览器发送的HTTP Accept头部的Django中间件。

项目描述

docs

Documentation Status

tests

Travis-CI Build Status Requirements Status
Coverage Status

package

PyPI Package latest release PyPI Package monthly downloads PyPI Wheel Supported versions Supported implementations

A Django middleware that inspects the HTTP Acept headers sent by browsers. It adds a new method to each request instance called accepts(str) which can be used to determine if a certain mimetype is accepted by the user agent that issued the request.

安装

pip install django-accept-header

使用

首先将中间件添加到您的 settings.py 文件中

MIDDLEWARE_CLASSES = (
    # ...
    'django_accept_header.middleware.AcceptMiddleware',
)

检查用户代理是否接受 text/plain MIME类型

def some_view(request):
    if request.accepts('text/plain'):
        # do something

也可以使用接受的MIME类型的有序列表

def some_view(request):
    for media_type in request.accepted_types:
        # do something

有关如何使用媒体类型,请参阅完整文档。

文档

https://django-accept-header.readthedocs.org/

开发

要运行所有测试,请运行

tox

0.3.0 / 2016-02-02

  • 将包名更改为django-accept-header。

  • 将默认测试版本设置为python3.5。

0.1.0 / 2015-11-26

  • 首次在PyPI上发布。

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分布

django-accept-header-0.3.2.tar.gz (11.8 kB 查看散列值)

上传时间 源代码

构建分布

django_accept_header-0.3.2-py2.py3-none-any.whl (17.4 kB 查看散列值)

上传时间 Python 2 Python 3