C
C
Cube2016-05-26 15:41:50
Django
Cube, 2016-05-26 15:41:50

How to pass a variable to a parameter?

Good day.
There is a django-pageviews library - github
If you look at the source, you can see that the template tag takes a view parameter, {% pageviews_url 'param' %}that is, it {% pageviews_url '/news/325/' %}will display the number of views for a specific url, but if I try to do this in a loop and pass the variable: {% pageviews_url '{{ post.get_absolute_url }}' %}, then nothing works.

def pageviews_url(path):
    """
    Displays pageviews by url. Useful for list views.
    """
    try:
        hit = HitCount.objects.get(url=path)
        return hit.hits
    except HitCount.DoesNotExist:
        return 0

Apparently I'm missing something. Please help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question