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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The browscap files can be read by the pythong ConfigParser library and are updated regularly.
http://browsers.garykeith.com/downloads.asp
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
Then in middleware
BCAP=browsecap.BrowserCapabilitues()
class UAMiddleware:
def process_request(self,request):
request.browser=BCAP(request.META.get('HTTP_USER_AGENT',''))
and in view..
if request.browser.is_mobile():
...