Tuesday, August 23, 2011

Re: why can't I access a dictionary with an initial form field value from my django template?

Thanks, Reinout.

I wound up creating a custom "getter" filter so I could do {{ MYDICT|
get:myform.somefiled.value }} - which I'm surprised isn't a built-in,
actually. But I think your suggestion is a good alternative.

Tony

On Aug 23, 1:40 pm, Reinout van Rees <rein...@vanrees.org> wrote:
> On 23-08-11 21:16, Tony Schmidt wrote:
>
> > I thought this should be the proper syntax in my template:
>
> > {{ MYDICT.myform.somefield.value }}
>
> > But I get a "can't parse remainder error."
>
> > Just putting {{ myform.somefield.value }} gives me "3" and {{ MYDICT.
> > 3 }} gives me the dictionary value I want.
>
> > Am I missing something?
>
> MYDICT.myform looks up an 'myform' attribute on MYDICT or the 'myform'
> key in the MYDICT dictionary. Which doesn't exist.
>
> There's no way the template language can know that it first has to look
> up the last three items and then apply that to the first item. That's
> the basic problem.
>
> Best solution probably: just do the MYDICT[myform.somefield.value] in
> your view and pass the value to the template?
>
> Reinout
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org            http://www.nelen-schuurmans.nl/
> "If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment