dict values error in python 3.6

70 views
Skip to first unread message

Maurice Waka

unread,
Feb 27, 2019, 11:36:04 PM2/27/19
to web2py-users
Hallo,
While creating a db, 
def create():
    form
= SQLFORM(db.food_data,submit_button=T('Submit'))
    form
.element('input[value=Submit]')['_style']='background-color: #DA2128; color:#ffffff'
   
if form.process().accepted:
         response
.flash="form accepted"
         redirect
(URL('default', 'searching'))
   
return dict(form=form)



Trying to enter data, I got this error:

Traceback (most recent call last):
 
File "/home/mauricewaka/web2py/gluon/restricted.py", line 219, in restricted
 
exec(ccode, environment)
 
File "/home/mauricewaka/web2py/applications/HWell/views/generic.html", line 81, in <module>
TypeError: 'dict_values' object does not support i

ndexing

Kevin Keller

unread,
Feb 28, 2019, 5:54:16 AM2/28/19
to web2py-users
Seems a python3 vs python2 related error?


Can you try to run your app with python2 for testing please ?

Lovedie JC

unread,
Feb 28, 2019, 7:06:27 AM2/28/19
to web...@googlegroups.com
Ok on p2.
But I'm shifting to p3. 6

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Keller

unread,
Feb 28, 2019, 7:22:52 AM2/28/19
to web...@googlegroups.com
Ok, could you file an issue on github for. This please?


Leonel Câmara

unread,
Feb 28, 2019, 8:10:23 AM2/28/19
to web2py-users
Probably something misusing a dictionary values() method in your models. It's expecting a list which can be accessed that way but it's getting a dictionary values generator in python 3. Can we see your models?

Paul Ellis

unread,
Mar 1, 2019, 10:39:43 PM3/1/19
to web...@googlegroups.com
This is a issue with generic.html. In Python 3 dict.values() does not return a list it returns a dict_values object.

On line 10 of Generic.html wrap the values method call in list() and it works.

{{=BEAUTIFY(list(response._vars.values())[0])}}

also use session.flash="form accepted" or you won't see the flashed message after the redirect.

    if form.process().accepted:
         session
.flash="form accepted"

Maurice Waka

unread,
Mar 2, 2019, 12:52:00 AM3/2/19
to web...@googlegroups.com
Yes. It works!
Regards 

On Sat, 2 Mar 2019, 06:39 Paul Ellis <eddie....@gmail.com> wrote:
This is a issue with generic.html. In Python 3 dict.values() does not return a list it returns a dict_values object.

On line 10 of Generic.html wrap the values method call in list() and it works.

{{=BEAUTIFY(list(response._vars.values())[0])}}




--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/KwYsKUWgYnw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
Message has been deleted

Paul Ellis

unread,
Mar 3, 2019, 6:38:19 PM3/3/19
to web2py-users

On Sat, Mar 2, 2019 at 12:16 PM Kevin Keller <kell...@gmail.com> wrote:
Can someone file an issue on github and also attach the solution please? Thanks
Reply all
Reply to author
Forward
0 new messages