[Answer]-Django-likes: setup and error

1👍

Looks like you are running django-likes on Django 1.5 in which usage of takes_context parameter of inclusion_tag has changed

Note that when you’re using takes_context=True, there’s no need to
pass arguments to the template tag. It automatically gets access to
the context.

And likes template tag code is

@register.inclusion_tag('likes/inclusion_tags/likes_extender.html', takes_context=True)
def likes(context, obj, template=None):
    if template is None:
        template = 'likes/inclusion_tags/likes.html'
    request = context['request']
    import_js = False
    if not hasattr(request, '_django_likes_js_imported'):
        setattr(request, '_django_likes_js_imported', 1)
        import_js = True
    context.update({
        'template': template,
        'content_obj': obj,
        'likes_enabled': likes_enabled(obj, request),
        'can_vote': can_vote(obj, request.user, request),
        'content_type': "-".join((obj._meta.app_label, obj._meta.module_name)),
        'import_js': import_js
    })
    return context

which was OK in Django 1.4

Update

The easiest solution is downgrading Django. If you want to stay with Django 1.5 you’ll have to modify

def likes(context, obj, template=None):

to and lern it to get obj from context

def likes(context):

    obj = context['likes_object']
    ...

In template you can pass variable with with tag

{% with likes_object = submission %}
    {% likes %}
{% endwith %}
👤twil

Leave a comment