django variable in template -
i m passing varible view ,to template. when m printing {{ subject.i.id }} not working. plz asap. thanks.
# view return render_to_response( 'feedback/feedback.html', {'subjects': subject_list, 'n': n, 'list': sub_list, 'i': 0}, context_instance=requestcontext(request)) # template {% s in list %} <div id="{{ subjects.i.id }}"> {% subject in s %} <div> {{ subject }} </div> {% endfor %} </div> {% endfor %}
you need template filter work
my template filter similar case:
import re django import template django.conf import settings numeric_test = re.compile("^\d+$") register = template.library() def getattribute(value, arg): """gets attribute of object dynamically string name""" if hasattr(value, str(arg)): return getattr(value, arg) elif hasattr(value, 'has_key') , value.has_key(arg): return value[arg] elif numeric_test.match(str(arg)) , len(value) > int(arg): return value[int(arg)] else: return settings.template_string_if_invalid register.filter('getattribute', getattribute) # in template {{ folder_info|getattribute:folder.id }}
Comments
Post a Comment