Django软件包,可以轻松识别访客的浏览器、操作系统和设备信息(手机、平板电脑或具有触摸功能)。
django-user-agents-last的Python项目详细描述
public version 0.3.1
===
fork:https://github.com/selwin/django-user-agents
===
===一个django包,可以轻松识别访问者的浏览器、操作系统和设备信息,
包括访客是否使用手机、平板电脑或可触摸设备。在幕后,
它使用"用户代理"https://github.com/selwin/python user agents>;` `.
installation
===
1。安装"django用户代理",您必须确保首先安装"用户代理":
pip install django user agents
2。配置"settings.py":
…代码块::python
已安装的应用程序=(
其他应用程序…
"django_用户代理",
)
缓存后端是可选的,但建议加快用户代理解析
caches={
'默认值':{
'后端':'django.core.cache.backends.memcached.memcacheddcache',
'位置':'127.0.0.1:11211',
}
}
如果未指定默认值,则将使用缓存别名。设置为"none"将禁用缓存。
用户代理缓存=默认值
用法
=
代码块::python
中间件类=(
其他中间件…
"django_user_agents.middleware.useragentmiddleware",
)
一个"user_agent"属性现在将添加到"request"中,您可以在"views.py"中使用该属性:
。代码块::python
def my_view(请求):
true
request.user_agent.is_pc返回false
request.user_agent.is_bot返回false
访问用户代理的浏览器属性
request.user_agent.browser返回浏览器(family=u'mobile safari',version=(5,1),version_string=(5.1')
request.user_agent.browser.family返回"mobile safari"
request.user_agent.browser.version返回(5,1)
请求.用户代理.浏览器.版本字符串返回"5.1"
request.user_agent.os.version返回(5,1)
request.user_agent.os.version嫒u string返回"5.1"
设备属性
request.user_agent.device嫒返回设备(family='iphone')
request.user_agent.device.family嫒返回"iphone"
`` django.core.context\u processors.request``enabled,``user\u agent`
也将通过``request```在模板中提供:
{%if request.user\u agent.is懔mobile%}
在此处执行操作…
{%endif%}
``带有"get-user-agent",它接受一个
``request``参数并返回一个"useragent"实例。示例用法:
…代码块::python
#做其他事情……
模板使用
----
``django-user_agents``附带了一些模板过滤器:
*``是mobile`
*``是`平板`
*``是`触摸`功能`
*``是`个人电脑`
*``是`机器人`
>您可以像使用任何其他django模板过滤器一样使用所有这些过滤器::
{%加载用户代理}
{%如果请求是`移动}
移动设备内容…
{%endif%}
{%如果请求是Tablet%}
Tablet内容…
{%endif%}
{%如果请求是PC%}
PC内容…
{%endif%}
{%if请求是Touch功能%}
可触摸设备内容…
{%endif%}
{%if请求是"bot%}
bot的东西……
{%endif%}
您可以在"here<;https://github.com/selwin/python user agents>;` `.
代码块::console
`which django admin.py`test django_user_agents--settings=django_user_agents.tests.settings--pythonpath=.
===
<0.3.1
----
*修复了请求没有元属性时的错误
<0.3.0
----
*python 3,感谢@hwkns!
0.2.2
----
*修复了当用户代理超过250个字符时导致缓存集/读取失败的错误
<0.2.1
----
*修复了打包
>0.2.0
----
*添加了模板过滤器
*在utils.py
0.1.1
----
*修复了"keyerror"异常,在"http用户代理"为空的情况下,`
<0.1
--
*初始版本
===
fork:https://github.com/selwin/django-user-agents
包括访客是否使用手机、平板电脑或可触摸设备。在幕后,
它使用"用户代理"https://github.com/selwin/python user agents>;` `.
installation
===
1。安装"django用户代理",您必须确保首先安装"用户代理":
2。配置"settings.py":
…代码块::python
已安装的应用程序=(
其他应用程序…
"django_用户代理",
)
缓存后端是可选的,但建议加快用户代理解析
caches={
'默认值':{
'后端':'django.core.cache.backends.memcached.memcacheddcache',
'位置':'127.0.0.1:11211',
}
}
如果未指定默认值,则将使用缓存别名。设置为"none"将禁用缓存。
用户代理缓存=默认值
用法
=
代码块::python
中间件类=(
其他中间件…
"django_user_agents.middleware.useragentmiddleware",
)
一个"user_agent"属性现在将添加到"request"中,您可以在"views.py"中使用该属性:
。代码块::python
def my_view(请求):
true
request.user_agent.is_pc返回false
request.user_agent.is_bot返回false
访问用户代理的浏览器属性
request.user_agent.browser返回浏览器(family=u'mobile safari',version=(5,1),version_string=(5.1')
request.user_agent.browser.family返回"mobile safari"
request.user_agent.browser.version返回(5,1)
请求.用户代理.浏览器.版本字符串返回"5.1"
request.user_agent.os.version返回(5,1)
request.user_agent.os.version嫒u string返回"5.1"
设备属性
request.user_agent.device嫒返回设备(family='iphone')
request.user_agent.device.family嫒返回"iphone"
`` django.core.context\u processors.request``enabled,``user\u agent`
也将通过``request```在模板中提供:
{%if request.user\u agent.is懔mobile%}
在此处执行操作…
{%endif%}
``带有"get-user-agent",它接受一个
``request``参数并返回一个"useragent"实例。示例用法:
…代码块::python
#做其他事情……
模板使用
----
``django-user_agents``附带了一些模板过滤器:
*``是mobile`
*``是`平板`
*``是`触摸`功能`
*``是`个人电脑`
*``是`机器人`
>您可以像使用任何其他django模板过滤器一样使用所有这些过滤器::
{%加载用户代理}
{%如果请求是`移动}
移动设备内容…
{%endif%}
{%如果请求是Tablet%}
Tablet内容…
{%endif%}
{%如果请求是PC%}
PC内容…
{%endif%}
{%if请求是Touch功能%}
可触摸设备内容…
{%endif%}
{%if请求是"bot%}
bot的东西……
{%endif%}
您可以在"here<;https://github.com/selwin/python user agents>;` `.
代码块::console
`which django admin.py`test django_user_agents--settings=django_user_agents.tests.settings--pythonpath=.
<0.3.1
----
*修复了请求没有元属性时的错误
<0.3.0
----
*python 3,感谢@hwkns!
0.2.2
----
*修复了当用户代理超过250个字符时导致缓存集/读取失败的错误
<0.2.1
----
*修复了打包
>0.2.0
----
*添加了模板过滤器
*在utils.py
0.1.1
----
*修复了"keyerror"异常,在"http用户代理"为空的情况下,`
<0.1
--
*初始版本