Reputation: 109
Please help to find the reason of error. Have two objects which ones returning from my view :
def managment_users_form(request):
users = User.objects.all()
usersinfo = usersinfo_model.objects.all()
count_objects = users.count()
if request.user.is_authenticated:
username = request.user.username
context = {
'users': users,
'usersinfo': usersinfo,
'count_objects': count_objects,
}
return render(request, 'users.html', context)
else:
return redirect('login_form')
And on my template I want to make for cycle from first one and filter by id in cycle another one. First is working well, but second one I'm getting error when try to use filter.
Teamplate
{% for user in users %}
<div class="">
<h4 class="m-b-5">{{ user.first_name }} {{ user.last_name }}</h4>
<p class="text-muted">{{ useremp|user_info_filter:user.id }} <span></p>
</div>
{% endfor %}
filter
from django import template
register = template.Library()
@register.filter(name='user_info_filter')
def user_info_filter(useremp, id):
return useremp.filter(user_id=id)
Please help to understand the mistake. Error is : "Invalid filter: 'user_info_filter'"
Upvotes: 1
Views: 343
Reputation: 560
Did you add the filter to settings.py? It's required from 1.9 Django
ex :
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'libraries':{
'filter': 'project_name.templatetags.filter',
}
},
Upvotes: 2