什么是django的好的User-Agent解析插件 [英] What's a good User-Agent parsing plugin for django

查看:380
本文介绍了什么是django的好的User-Agent解析插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可以推荐的User-Agent-String解析插件或中间件。现在我正在使用 django-smartagent ,但其字典不完整并且不经常更新。

Is there a User-Agent-String parsing plugin or middleware that you can recommend. Right now I am using django-smartagent, but its dictionary is not complete and not updated very often.

推荐答案

可以通过pythong ConfigParser库读取browscap文件,并定期更新。

The browscap files can be read by the pythong ConfigParser library and are updated regularly.

http://browsers.garykeith.com/downloads.asp

这是一个模块,显示使用ConfigParser从较旧的djangosnippet发布(267)稍微修改的版本来读取,以便更容易地查找browscap.ini文件

This is a module that shows using ConfigParser to read, from a older djangosnippet posting (267) slightly modified version to allow for easier 'finding' of the browscap.ini file

http://pastebin.com/viD5F7nV

然后在中间件

BCAP=browsecap.BrowserCapabilitues()

class UAMiddleware:
    def process_request(self,request):
        request.browser=BCAP(request.META.get('HTTP_USER_AGENT',''))

并查看..

if request.browser.is_mobile():
    ...

这篇关于什么是django的好的User-Agent解析插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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