Вопрос

I've installed the Django-voting app found here, but I am unable to get the template tags to work. For example, from what I've read, simply running

{% load voting_tags %}
{% score_for_object object_name as score %}

should work, but it errors with a simple Invalid block tag: 'score_for_object'.

I have downloaded the app and run setup.py and verified that it installed by casting a vote in the Django Python shell. I have also added 'voting' to the list of installed apps, and moved the 'voting' folder to my project. I have also tried adding "voting.templatetags.voting_tags", to my list of template context processors in settings.py.

Am I missing something? According to the readme, there is no more setup after simply ensuring that the module is present on Python path (which I believe installing it with setup.py provides), adding it to installed_apps, and running syncdb. Any help is greatly appreciated.

Edit: I have tried to use the command {% load voting_tags %} in my template. Note that the location of the tags in the voting module is voting/templatetags/voting_tags.py. The application now gives me an error:

'voting_tags.py' is not a valid tag library: Template library voting_tags.py not 
found, tried django.templatetags.voting_tags.py, 
   django.contrib.staticfiles.templatetags.voting_tags.py,voting.templatetags.voting_tags.py,
django.contrib.admin.templatetags.voting_tags.py

Notice that it is actually trying the correct directory, being voting.templatetags.voting_tags.py, but it is apparently not being registered as valid. It does contain the required code as specific in the Django Documentation, namely:

from django import template
register = template.Library()

Nevertheless, I am having no luck. Why might a library of tags not be considered a valid tag library? It seems to me that it either lacks the correct code to make it a tag library (which, as shown above, it does possess), or there is some sort of path issue where voting.templatetags.voting_tags.py is somehow not finding a file at all. Any insight would help me out quite a bit.

Thanks,

ParagonRG

Это было полезно?

Решение

Template tags are different from template context processors. Have you loaded the template tag?

{% load voting_tags %} 

Note that {% load voting_tags.py %} is incorrect also.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top