Invalid filter: '__pypugjs_iter'
jhotujec opened this issue · 14 comments
- pypugjs version: Latest
- Django version: 1.9.1
- Python version: 2.7
- Operating System: Ubuntu
Description
Getting Invalid filter: '__pypugjs_iter'
when using each
in template when i try to iterate over a list of dicts.
div.page-header.container-fluid
h4.page-title {{ page_header.title }}
div.page-subtitle
ul.list-inline.mb-0
each s in page_header.subtitle
p Test
Looks like the package is adding a filter on values.. what is the purpose of that?
<div class="page-subtitle">
<ul class="list-inline mb-0"></ul>{% for s in page_header.subtitle\|__pypugjs_iter:1 %}
<p>Test</p>{% endfor %}
</div>
There is no each in python. Use
for s in page_header.subtitle
and indent the for inside the ul if u actually want to create internal elements
same error, and each
is pugjs syntax which gets evaluated to django template
{% for s in page_header.subtitle\|__pypugjs_iter:1 %}
<p>Test</p>{% endfor %}
what is subtitle supposed to be? is it some sort of list? What are you trying to do?
@kakulukia thanks for taking time to checking into this issue, i appreciate it :) Yes, it's a list of dicts. I'm actually converting a django templates to .pug so everything is working with django, so I dont think there's problem with that.. as far I can tell there's a problem with pug filter being applied to subtitle
.
Is there something that is supposed to be loaded in the template to be able to iterate over a list?
I dont have an idea of what might be wrong then .. please check if page_header and page_header.subtitle is actually available in the template and filled with what you expect it to be.
I've checked, everything seems to be ok. it looks like filters aren't included for some reason? is this working for you, iteration?
Sure, it should just work and it does in this packages test cases. Are you sure you did setup the Django configuration as mentioned in the docs? Try to reproduce the error with a simple list.
If that all aint working out. Please take the time to reproduce the error with my project template where everything is setup as needed for pypugjs to work (https://github.com/kakulukia/django-default-project). If you can reproduce it, commit that and i will have a look. If not, look for the diff versus your project.
Any progress in reproducing the error so i could have a look at it myself? Or did you even solve it?
I had the same problem and in my case it was because I was missing the builtins
sections in settings.py.
Adding it made it work for me.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'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',
],
'loaders': [
# PyPugJS part: ##############################
('pypugjs.ext.django.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
))
],
'builtins': [
'pypugjs.ext.django.templatetags',
],
},
},
]
How did you end up not having the builtins in the config, since it documented that way in the installation section?
How did you end up not having the builtins in the config, since it documented that way in the installation section?
Well, basically because of the comment saying # PyPugJS part: #############################
, because of the indentation it looks like only the part below is the one corresponding to pypugjs. My mistake, though.
understand .. i will put it one level up :)