Django `with` does not recognize keyword argument

I have the following code in my template:

{% include "entry_table/cell.html" with data_items = data_fields class="entry_table_title" only%} 

Which gives me the following error:

 "with" in 'include' tag needs at least one keyword argument. 

I tried replacing data_field (which is the variable that I passed in the context) with a string, just in case that caused this problem, but even if I do it:

 {% include "entry_table/cell.html" with data_items = "unicorn" class="entry_table_title" only%} 

I still get the same error. The only thing that fixes the problem is to completely get rid of data_items, as in:

 {% include "entry_table/cell.html" with class="entry_table_title" only%} 

So what is the problem?

NOTE. I just realized that data_items is also a variable that is passed to the context of the page calling another template, but when I changed the name to something else, it still doesn't work. So this is not a problem.

+4
source share
2 answers

It seems that Django is pretty picky about this gap. If I change ...

 {% include "entry_table/cell.html" with data_items = data_fields class="entry_table_title" only%} 

... before...

 {% include "entry_table/cell.html" with data_items=data_fields class="entry_table_title" only%} 

... it works for me.

+10
source

I had a very similar problem. I only used dashes, which apparently are not allowed in variable names.

I know that this is an older question, and he has already received a sufficient answer, but it is closely related and comes with the search, so for the sake of posterity ...

 {% include "partials/forum-panel-header.html" with forum-name="demo name" forum-thread-count="22" forum-post-count="30" %} 

It was necessary to change the dash to underscores ...

 {% include "partials/forum-panel-header.html" with forum_name="demo name" forum_thread_count="22" forum_post_count="30" %} 

It would be nice to know this before I wrote many variable names this way, and I had to go back through all the attached files to fix them.

Of course, I could find the answer if I looked, but at that time I did not even realize that I needed an answer.

Well, then I found the answer (when I realized that there was a problem) to another post here that appeared in the search under this (which is why I wrote on this).

0
source

Source: https://habr.com/ru/post/1486399/


All Articles