Good evening!
First, I would like you to help me improve this topic, if necessary.
Well, I work with Django 1.8.5, Python 3.4, virtualenv and other dependencies as well.
My problem is. I have two custom template tags, one works, one does not. What works is "companies_i_recommend". Code below:
from django import template
from portalcom.companies.models import Recommend
register = template.Library()
@register.inclusion_tag('companies/templatetags/companies_i_recommend.html')
def companies_i_recommend(user):
recommendations = Recommend.objects.filter(user=user).count()
context = {
'recommendations': recommendations,
}
return context
@register.assignment_tag
def i_recommend(user, company):
user = user
company = company
recommend = Recommend.objects.filter(user=user, company=company)
In the browser, trying to use a tag that does not work, I get a template syntax error saying that the tag is not valid. If I use the Python shell, I get this error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: cannot import name 'i_recommend'
My goal is to put the "recommend" variable in the context of multiple pages, since I'm trying to load it into a base.html file.
So can anyone help with this mystery? Thank you in advance!