Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I have a dictionary with a number of characteristics:

sort_options = SortedDict([ ("importance" , ("Importance" , "warning-sign" , "importance")), ("effort" , ("Effort" , "wrench" , "effort")), ("time_estimate" , ("Time Estimate" , "time" , "time_estimate")), ]) 

I also have a list of actions as a query result. Each action has these attributes; In my template, I can call {{ action.effort }} or {{ action.time_estimate }} and get a result.

I'm iterating through my sort_options to populate twitter bootstrap icons:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {% endfor %} 

But I also want to display the action value for each of these attributed. Essentially, something like:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action.key }} {% endfor %} 

Where key would resolve to "importance" or "effort". I know this doesn't work. So I was trying to leverage the solution presented in this questionthis question.

The solution proposed a template filter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash) {{ user|hash:item }} 

Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

I tried the following:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action|hash:key }} {% endfor %} 

But got an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template filter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary:

[<Action: Action_one>, <Action: Task_two>...] 

Is there a way to force the template to pass the full object to the template tag?

I have a dictionary with a number of characteristics:

sort_options = SortedDict([ ("importance" , ("Importance" , "warning-sign" , "importance")), ("effort" , ("Effort" , "wrench" , "effort")), ("time_estimate" , ("Time Estimate" , "time" , "time_estimate")), ]) 

I also have a list of actions as a query result. Each action has these attributes; In my template, I can call {{ action.effort }} or {{ action.time_estimate }} and get a result.

I'm iterating through my sort_options to populate twitter bootstrap icons:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {% endfor %} 

But I also want to display the action value for each of these attributed. Essentially, something like:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action.key }} {% endfor %} 

Where key would resolve to "importance" or "effort". I know this doesn't work. So I was trying to leverage the solution presented in this question.

The solution proposed a template filter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash) {{ user|hash:item }} 

Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

I tried the following:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action|hash:key }} {% endfor %} 

But got an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template filter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary:

[<Action: Action_one>, <Action: Task_two>...] 

Is there a way to force the template to pass the full object to the template tag?

I have a dictionary with a number of characteristics:

sort_options = SortedDict([ ("importance" , ("Importance" , "warning-sign" , "importance")), ("effort" , ("Effort" , "wrench" , "effort")), ("time_estimate" , ("Time Estimate" , "time" , "time_estimate")), ]) 

I also have a list of actions as a query result. Each action has these attributes; In my template, I can call {{ action.effort }} or {{ action.time_estimate }} and get a result.

I'm iterating through my sort_options to populate twitter bootstrap icons:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {% endfor %} 

But I also want to display the action value for each of these attributed. Essentially, something like:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action.key }} {% endfor %} 

Where key would resolve to "importance" or "effort". I know this doesn't work. So I was trying to leverage the solution presented in this question.

The solution proposed a template filter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash) {{ user|hash:item }} 

Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

I tried the following:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action|hash:key }} {% endfor %} 

But got an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template filter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary:

[<Action: Action_one>, <Action: Task_two>...] 

Is there a way to force the template to pass the full object to the template tag?

clarifying the question
Source Link
Ed.
  • 4.6k
  • 11
  • 62
  • 81

I'm trying to leverage the solution presented inI have a dictionary with a number of characteristics:

sort_options = SortedDict([ ("importance" , ("Importance" , "warning-sign" , "importance")), ("effort" , ("Effort" , "wrench" , "effort")), ("time_estimate" , ("Time Estimate" , "time" , "time_estimate")), ]) 

I also have a list of actions as a query result. Each action has these attributes; In my template, I can call this question{{ action.effort }} or {{ action.time_estimate }} and get a result.

My problem is thatI'm iterating through my object seemssort_options to be a different type of dictionary? Where the question used a dictionary that looked like sopopulate twitter bootstrap icons:

{'item1':% 3for key, 'name':icon 'username',in 'item2':sort_options.items 4%} <i class="icon-{{ icon.1 }}"></i> {% endfor %} 

My object is a query resultBut I also want to display the action value for each of these attributed. Essentially, something like:

[<Action:{% Action_one>for key, <Action:icon Task_two>in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action.]key }} {% endfor %} 

Where key would resolve to "importance" or "effort". I know this doesn't work. So I was trying to leverage the solution presented in this question.

The solution proposed a template filter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash) {{ user|hash:item }} 

But when I try something similar,Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

I gettried the following:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action|hash:key }} {% endfor %} 

But got an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template filter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary. Is:

[<Action: Action_one>, <Action: Task_two>...] 

Is there a way to force the template to pass the full object to the template tag?

I'm trying to leverage the solution presented in this question.

My problem is that my object seems to be a different type of dictionary? Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

My object is a query result:

[<Action: Action_one>, <Action: Task_two>...] 

The solution proposed a template filter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash) {{ user|hash:item }} 

But when I try something similar, I get an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template filter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary. Is there a way to force the template to pass the full object to the template tag?

I have a dictionary with a number of characteristics:

sort_options = SortedDict([ ("importance" , ("Importance" , "warning-sign" , "importance")), ("effort" , ("Effort" , "wrench" , "effort")), ("time_estimate" , ("Time Estimate" , "time" , "time_estimate")), ]) 

I also have a list of actions as a query result. Each action has these attributes; In my template, I can call {{ action.effort }} or {{ action.time_estimate }} and get a result.

I'm iterating through my sort_options to populate twitter bootstrap icons:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {% endfor %} 

But I also want to display the action value for each of these attributed. Essentially, something like:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action.key }} {% endfor %} 

Where key would resolve to "importance" or "effort". I know this doesn't work. So I was trying to leverage the solution presented in this question.

The solution proposed a template filter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash) {{ user|hash:item }} 

Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

I tried the following:

{% for key, icon in sort_options.items %} <i class="icon-{{ icon.1 }}"></i> {{ action|hash:key }} {% endfor %} 

But got an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template filter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary:

[<Action: Action_one>, <Action: Task_two>...] 

Is there a way to force the template to pass the full object to the template tag?

I'm trying to leverage the solution presented in this question.

My problem is that my object seems to be a different type of dictionary? Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

My object is a query result:

[<Action: Action_one>, <Action: Task_two>...] 

The solution proposed a template tagfilter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash)  {{ user|hash:item }} 

But when I try something similar, I get an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template tagfilter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary. Is there a way to force the template to pass the full object to the template tag?

I'm trying to leverage the solution presented in this question.

My problem is that my object seems to be a different type of dictionary? Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

My object is a query result:

[<Action: Action_one>, <Action: Task_two>...] 

The solution proposed a template tag:

def hash(h,key): if key in h: return h[key] else: return None {{ user|hash:item }} 

But when I try something similar, I get an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template tag is getting just one attribute of the object (likely the name) as opposed to the whole dictionary. Is there a way to force the template to pass the full object to the template tag?

I'm trying to leverage the solution presented in this question.

My problem is that my object seems to be a different type of dictionary? Where the question used a dictionary that looked like so:

{'item1': 3, 'name': 'username', 'item2': 4} 

My object is a query result:

[<Action: Action_one>, <Action: Task_two>...] 

The solution proposed a template filter:

def hash(h,key): if key in h: return h[key] else: return None register.filter(hash)  {{ user|hash:item }} 

But when I try something similar, I get an error:

Caught TypeError while rendering: argument of type 'Action' is not iterable 

I believe this is because the template filter is getting just one attribute of the object (likely the name) as opposed to the whole dictionary. Is there a way to force the template to pass the full object to the template tag?

Source Link
Ed.
  • 4.6k
  • 11
  • 62
  • 81
Loading