Skip to content


Repository files navigation

Pinax Likes

CircleCi Codecov

Table of Contents

About Pinax

Pinax is an open-source platform built on the Django Web Framework. It is an ecosystem of reusable Django apps, themes, and starter project templates. This collection can be found at

Important Links

Where you can find what you need:


pinax-likes is a liking app for Django, allowing users to "like" and "unlike" any model instance in your project. Template tags provide the ability to see who liked an object, what objects a user liked, and more.

pinax-likes is not a karma system. It does not have down-voting.


Supported Django and Python Versions

Django / Python 3.6 3.7 3.8
2.2 * * *
3.0 * * *



To install pinax-likes:

    $ pip install pinax-likes

Add pinax.likes to your INSTALLED_APPS setting:

        # other apps

Add the models that you want to be likable to PINAX_LIKES_LIKABLE_MODELS in your settings file:

        "app.Model": {}  # override default config settings for each model in this dict

Add pinax.likes.auth_backends.CanLikeBackend to your AUTHENTICATION_BACKENDS (or use your own custom version checking against the pinax.likes.can_like permission):

        # other backends

Add pinax.likes.urls to your project urlpatterns:

    urlpatterns = [
        # other urls
        url(r"^likes/", include("pinax.likes.urls", namespace="pinax_likes")),


Add each model that you want to be likable to the PINAX_LIKES_LIKABLE_MODELS setting:

        "profiles.Profile": {},
        "videos.Video": {},
        "biblion.Post": {},

Display "like" widgets in your Django templates. Suppose you have a detail page for a blog post. First load the template tags:

    {% load pinax_likes_tags %}

In the body where you want the liking widget to go, add:

    {% likes_widget request.user post %}

Finally, ensure you have eldarion-ajax installed:

Eldarion AJAX

The likes_widget templatetag above and the "toggle like" view both conform to an AJAX response that eldarion-ajax understands. Furthermore, the templates that ship with this project will work seemlessly with eldarion-ajax. Include the eldarion-ajax.min.js Javascript package in your base template:

    {% load staticfiles %}
    <script src="{% static "js/eldarion-ajax.min.js" %}"></script>

and include eldarion-ajax in your site JavaScript:


Using Eldarion AJAX is optional. You can roll your own JavaScript handling as the view also returns data in addition to rendered HTML. Furthermore, if you don't want ajax at all the view will handle a regular POST and perform a redirect.


Both of these signals are sent from the Like model in the view that processes the toggling of likes and unlikes.


This signal is sent immediately after the object is liked and provides the single kwarg of like which is the created Like instance.


This signal is sent immediately after the object is unliked and provides the single kwarg of object which is the object that was just unliked.



Returns the number of likes for a given object:

    {{ obj|likes_count }}

Template Tags


An assignment tag that fetches a list of likes for a given object:

    {% who_likes car as car_likes %}

    {% for like in car_likes %}
        <div class="like">{{ like.sender.get_full_name }} likes {{ car }}</div>
    {% endfor %}


The likes tag will fetch into a context variable a list of objects that the given user likes. This tag has two forms:

  1. Obtain likes of every model listed in settings.PINAX_LIKES_LIKABLE_MODELS:
    {% likes user as objs %}
  1. Obtain likes for specific models:
    {% likes user "app.Model" as objs %}
    {% likes request.user "app.Model" as objs %}
    {% for obj in objs %}
        <div>{{ obj }}</div>
    {% endfor %}


This renders a like. It combines well with the likes templatetag for showing a list of likes:

    {% likes user as like_list %}
        {% for like in like_list %}
            <li>{% render_like like %}</li>
        {% endfor %}

The render_like tag looks in the following places for the template to render. Any of them can be overwritten as needed, allowing you to customize the rendering of the like on a per model and per application basis:

  • pinax/likes/app_name/model.html
  • pinax/likes/app_name/like.html
  • pinax/likes/_like.html


This renders a fragment of HTML the user clicks on to unlike or like objects. It only has two required parameters, the user and the object:

    {% likes_widget user object %}

It renders pinax/likes/_widget.html. A second form for this templatetag specifies the template to be rendered:

    {% likes_widget request.user post "pinax/likes/_widget_brief.html" %}


This template tag decorates an iterable of objects with a liked boolean indicating whether or not the specified user likes each object in the iterable:

    {% liked objects by request.user as varname %}
    {% for obj in varname %
        <div>{% if obj.liked %}* {% endif %}{{ obj.title }}</div>
    {% endfor %}



A dictionary keyed by "<appname.model>". Each model value is a dictionary containing context keys and values.

Context value keys are CSS element names used in template rendering for each model:


Here is an example from the test settings used on this project found in

        "auth.User": {
            "like_text_on": "unlike",
            "css_class_on": "fa-heart",
            "like_text_off": "like",
            "css_class_off": "fa-heart-o",
            "allowed": lambda user, obj: True
        "tests.Demo": {
            "like_text_on": "unlike",
            "css_class_on": "fa-heart",
            "like_text_off": "like",
            "css_class_off": "fa-heart-o"


pinax-likes uses minimal template snippets rendered with template tags.

Default templates are provided by the pinax-templates app in the likes section of that project.

Reference pinax-templates installation instructions to include these templates in your project.

View live pinax-templates examples and source at Pinax Templates!

Customizing Templates

Override the default pinax-templates templates by copying them into your project subdirectory pinax/likes/ on the template path and modifying as needed.

For example if your project doesn't use Bootstrap, copy the desired templates then remove Bootstrap and Font Awesome class names from your copies. Remove class references like class="btn btn-success" and class="icon icon-pencil" as well as bootstrap from the {% load i18n bootstrap %} statement. Since bootstrap template tags and filters are no longer loaded, you'll also need to update {{ form|bootstrap }} to {{ form }} since the "bootstrap" filter is no longer available.




Change Log


  • Drop Django 1.11, 2.0, and 2.1, and Python 2,7, 3.4, and 3.5 support
  • Add Django 2.2 and 3.0, and Python 3.6, 3.7, and 3.8 support
  • Update packaging configs
  • Direct users to community resources


  • Change receiver_object_id type to BigIntegerField


  • Add file


  • Add django>=1.11 to requirements
  • Improve documentation markup
  • Remove doc build support
  • Update CI config
  • Replace pinax-theme-bootstrap with pinax-templates for testing


  • Drop Django 1.8 and 1.10 support
  • Improve documentation


  • Correct LONG_DESCRIPTION app title


  • Add Django 2.0 compatibility testing
  • Drop Django 1.9 and Python 3.3 support
  • Move documentation into README
  • Convert CI and coverage to CircleCi and CodeCov
  • Add PyPi-compatible long description


  • adds context and request to the likes_widget template tag


  • Improve documentation


  • Converted documentation to Markdown format


  • Converted to Django class-based generic views.
  • Added URL namespace."pinax_likes"
  • Added tests.
  • Dropped support for Django 1.7
  • Added in order to remove django-user-accounts dependency.


  • like_text_off and css_class_off are passed into widget even if can_like is False.
  • PINAX_LIKES_LIKABLE_MODELS entries now take an optional extra value allowed whose value should be a callable taking user and obj and returning True or False depending on whether the user is allowed to like that particular object


  • Fixed regression causing error when widget displayed while unauth'd


  • Fixed deprecation warnings
  • Fixed unicode string
  • Added support for custom User models
  • Documentation updates


  • Added an


  • Added a likes\_widget\_brief to display a brief widget template (likes/\_widget\_brief.html)


  • Added a who\_likes template tag that returns a list of Like objects for given object


  • Made the link in the default widget template a bootstrap button


  • Fixed isinstance check to check models.Model instead of models.base.ModelBase
  • Added permission checking
  • Added rendering of HTML in the ajax response to liking
  • Got rid of all the js/css cruft; up to site owner now but ships with bootstrap/bootstrap-ajax enabled templates
  • Updated use of to

Backward Incompatibilities

  • Added an auth\_backend to check permissions, you can just add the likes.auth\_backends.PermCheckBackend and do nothing else, or you can implement your own backend checking the likes.can\_like permission against the object and user according to your own business logic.
  • No more likes_css, likes_js, or likes_widget_js tags.
  • PINAX_LIKES_LIKABLE_MODELS has changed from a list to a dict
  • likes_widget optional parameters have been removed and instead put into per model settings


  • Renamed likes\_css and likes\_widget to likes\_css and likes\_widget
  • Turned the JavaScript code in to a jQuery plugin, removed most of the initialization code from the individual widget templates to a external JavaScript file, and added a {% likes\_js %} tag to load this plugin.
  • Each like button gets a unique ID, so multiple like buttons can appear on a single page
  • The like form works without JavaScript.
  • Likable models need to be added to PINAX\_LIKES\_LIKABLE\_MODELS setting. This prevents users from liking anything and everything, which could potentially lead to security problems (eg. liking entries in permission tables, and thus seeing their content; liking administrative users and thus getting their username).
  • Added request objects to both object\_liked and object\_unliked signals.

Backward Incompatibilities

  • Pretty much all the template tags have been renamed and work slightly differently


  • Made it easier to get rolling with a like widget using default markup and JavaScript
  • Added returning the like counts for an object when it is liked or unliked so that the widget (either your own or using the one that ships with likes) can update via AJAX

Backward Incompatibilities

  • Removed likes\_ajax and likes\_form template tags so if you were using them and had written custom overrides in \_ajax.js and \_form.html you'll need to plan your upgrade accordingly.
  • Changed the url pattern, likes\_like\_toggle, for likes to not require the user pk, instead, the view handling the POST to this url, uses request.user.
  • Changed the ajax returned by the like\_toggle view so that it now just returns a single element: {"likes\_count": \<some-number\>}


  • Initial release


Contributing information can be found in the Pinax community health file repo.

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, the Pinax Project has a Code of Conduct. We ask you to treat everyone as a smart human programmer that shares an interest in Python, Django, and Pinax with you.

Connect with Pinax

For updates and news regarding the Pinax Project, please follow us on Twitter @pinaxproject and check out our Pinax Project blog.


Copyright (c) 2012-present James Tauber and contributors under the MIT license.