﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26505	django form dynamic attribute lookup	Igor Belo	nobody	"I'm facing an issue, and can't figure out how to solve it.

I have the following form in my application:
{{{
class ContentForm(ModelForm):
        class Meta:
            model = Content
            fields = ('url_1','url_2','url_3','url_4','url_5',)
            widgets = {
                'url_1': forms.URLInput(attrs={'class': 'form-control', 'maxlength': 100}),
                'url_2': forms.URLInput(attrs={'class': 'form-control', 'maxlength': 100}),
                'url_3': forms.URLInput(attrs={'class': 'form-control', 'maxlength': 100}),
                'url_4': forms.URLInput(attrs={'class': 'form-control', 'maxlength': 100}),
                'url_5': forms.URLInput(attrs={'class': 'form-control', 'maxlength': 100}),
            }
}}}
What I'm trying to do is to generate those url fields dynamically through a loop. I took [http://stackoverflow.com/questions/27324602/django-use-value-of-template-variable-as-part-of-another-variable-name/27324674#27324674 this] approach (which implements a template tag for dynamic attribute lookup):
{{{
    {% for i in 12345|make_list %}
        {% with url='url_'|add:i %}
          {{ form|getattribute:url }}
        {% endwith %}
    {% endfor %}
}}}
However it's not working. Django doesn't render the input field and complains that my form object doesn't have an attribute called `url_1` for example. If I call the `url_1` attribute for the same form directly it works. I checked it many times and the form object id is the same in all contexts (template, view and custom template tag).

The implementation of the `getattribute` template tag is the same as [http://stackoverflow.com/questions/844746/performing-a-getattr-style-lookup-in-a-django-template/ here].

ps.: django version running is 1.9.2"	Bug	closed	Forms	1.9	Normal	invalid	django-forms custom-templatetag dynamic-attribute-lookup		Unreviewed	0	0	0	0	0	0
