passing dictionary in URL not working. I Get a string

851 views
Skip to first unread message

António Ramos

unread,
Jul 19, 2011, 1:15:24 PM7/19/11
to web...@googlegroups.com
hello i have this in a view

<li>{{=A(amostra,_href=URL(r=request,c='amostra',f='get',vars={'amostra':amostra,'amostra_detalhe':Amostra[amostra]}))}} 

Amostra is a dictionary
amostra is every element in Amostra 
every amostra of Amostra is a dictionary


in this view i iterate over Amostra[amostra]['param1....paramN], etc with no problem.


in the controler amostra, function get i do 

print type(request.vars['amostra_detalhe'])

and i get <'str'>  and not <'dict'>

what the hell,
this way i cannot iterate over the params and get this error
string indices must be integers


Please help me.i´m stuck
thank you

António

Jonathan Lundell

unread,
Jul 19, 2011, 1:28:27 PM7/19/11
to web...@googlegroups.com

request.vars is simply a representation of a URL query string, which is a collection of key=value items, where key and value are both treated as strings.

You could presumably encode a dict into a string and decode it when it comes back, but you'll have to do that yourself (and the URL will be pretty ugly).

António Ramos

unread,
Jul 19, 2011, 1:37:20 PM7/19/11
to web...@googlegroups.com
So what is the best way to pass a dictionary from one page to the other?
can i do session.dictvar=mydictvar?

thank you
António

2011/7/19 Jonathan Lundell <jlun...@pobox.com>

Jonathan Lundell

unread,
Jul 19, 2011, 1:56:06 PM7/19/11
to web...@googlegroups.com
On Jul 19, 2011, at 10:37 AM, António Ramos wrote:
So what is the best way to pass a dictionary from one page to the other?
can i do session.dictvar=mydictvar?

Yes, as long as everything you put in there can be pickled.

Manuele Pesenti

unread,
Jul 21, 2011, 5:01:36 AM7/21/11
to web...@googlegroups.com
On 19/07/2011 19:37, Ant�nio Ramos wrote:
> So what is the best way to pass a dictionary from one page to the other?
> can i do session.dictvar=mydictvar?

http://docs.python.org/library/json.html

this is a solution I adopted sometimes... I hope it could be usefull :)

Manuele

António Ramos

unread,
Jul 21, 2011, 5:44:40 AM7/21/11
to web...@googlegroups.com
Thank you a lot.

2011/7/21 Manuele Pesenti <manuele...@gmail.com>

pbreit

unread,
Jul 21, 2011, 11:54:07 AM7/21/11
to web...@googlegroups.com
Do you plan to save the data to the DB or elsewhere at some point? I would suggest putting it in the DB or stuffing it insto session. The JSON thing is more for inter-application communication.
Reply all
Reply to author
Forward
0 new messages