Answer the question
In order to leave comments, you need to log in
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question