django-cacheback 和 django-hitcount 之间的简单集成
项目描述
django-popularity-mixin
django-cacheback 和 django-hitcount 之间的简单集成 django-cacheback 和 django-hitcount
作者: Basil Shubin
需求
您必须安装并配置 django-cacheback 和 django-hitcount,有关详细信息及设置说明,请参阅 django-cacheback 和 django-hitcount 文档。
安装
首先安装模块,最好是在虚拟环境中安装。它可以从PyPI安装
pip install django-popularity-mixin
设置
确保项目已配置为 django-cacheback 和 django-hitcount。
然后添加以下设置
INSTALLED_APPS += (
'popularity',
)
使用
可以使用 popularity.views.PopularityMixin 通过设置 count_hit 为 True 来异步执行计数击打的业务逻辑。
# views.py
from django.views.generic.detail import DetailView
from popularity.views import PopularityMixin
class CustomDetailView(PopularityMixin, DetailView):
count_hit = True # set to True if you want it to try and count the hit asynchronously
template_name = "template.html"
...
popularity.viwes.PopularityMixin 扩展了 Django 的通用 django.views.generic.detail.DetailView 并注入了一个额外的上下文变量 hitcount。
<!-- template.html -->
{# the primary key for the hitcount object #}
{{ hitcount.pk }}
{# the total hits for the object #}
{{ hitcount.total_hits }}
为了更细致地查看相关对象的命中次数,您可以使用 get_hit_count 模板标签。
{# remember to load the tags first #}
{% load popularity_tags %}
{# Return total hits for an object: #}
{% get_hit_count for [object] %}
{# Get total hits for an object as a specified variable: #}
{% get_hit_count for [object] as [var] %}
{# Get total hits for an object over a certain time period: #}
{% get_hit_count for [object] within ["days=1,minutes=30"] %}
{# Get total hits for an object over a certain time period as a variable: #}
{% get_hit_count for [object] within ["days=1,minutes=30"] as [var] %}
请参阅 示例 应用程序。此应用程序用于手动测试该包的功能。这也是一个好例子...
您需要 Django 1.8.1 或更高版本来运行它。它可能在旧版本上运行,但未经过测试。
贡献
如果您喜欢这个模块,已经分叉了它,或者想改进它,请让我们知道!也欢迎提交拉取请求。:-)
项目详情
关闭
django-popularity-mixin-0.1.8.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | be204bf21336e7c5e4bc5027027cfe22722402e49b6fc9e8a4dec8dc28de0eb4 |
|
MD5 | 4899c161aecce9564ae92f74485c2d92 |
|
BLAKE2b-256 | 6ea76bcbe23af096726731f6cd14297b2156606b0137fa82aa33d8a89bb82bd7 |
关闭
django_popularity_mixin-0.1.8-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5306df0cd588d57792af5961d6dd690b2823c949734332ce7e99d1bce234ffcc |
|
MD5 | c6e21eb30fe7ba26fdef806e4b83aa31 |
|
BLAKE2b-256 | a0ecf7bae238b05ba154f6eabdf8d314a0fe1fb58e9b7a7e56df29e27805e6b3 |