session object: can't hold session.variable

44 views
Skip to first unread message

philkane

unread,
Nov 2, 2019, 10:18:36 PM11/2/19
to web2py-users
Hi, I'm new to web2py & web development. I'm working through the "manual 5th edition" - simple examples on Windows 10 64 bit executable version of web2py. Any time I try to assign values to session variable it does not appear in other parts of the app. e.g. 
def first():
    ...
    ...
    session.visitor_name=request.vars.visitor_name
    redirect(URL('second'))
    ...

default/second.html
    ...
    <h1>Hello {{=session.visitor_name or "anonymous"}}</h1>


The code is so simple I'm pretty sure I'm getting the code right. No errors are being reported.  If I just use request.vars.visitor_name in second.html, it works fine. 

Any ideas what might be going on or what I can try?  

Getting frustrated so early in the learning process!!

Thanks

Phil

Jose C

unread,
Nov 3, 2019, 9:43:04 AM11/3/19
to web2py-users
In principle, that should work.  However you say you're new to this so some basic scenarios to check below.

1) Do you have a def second() controller where the variable is being overridden or deleted?  Or session.forget() is called?
2) Are you navigating to /default/first?visitor_name=phil (to cause the variable to be set in request.vars in on that page) and being redirected successfully to second?  Note that if request.vars.visitor_name is not passed in the url it assigns python None to session.visitor_name, which explains why you don't see it later.
3) Does your browser have cookies enabled and is accepting cookies from your dev server?  The session id is stored in the cookie and if that is not being passed back, then each page hit is a new session (with balnk session variables).
4) Try putting {{=response.toolbar()}} into your html pages.  This  generates a debug toolbar with the session and request contents in there (plus some other useful stuff)... might help troubleshoot.

HTH,

Jose

philkane

unread,
Nov 3, 2019, 10:35:47 AM11/3/19
to web...@googlegroups.com
Thanks Jose C,

I had tried/checked all of your suggestions to no avail. I have sinve posting, uninstalled Python 3.8.0 and reverted to Python 3.75 and re-run the same code and it all works as expected.  I can only assume there was a problem with 3.8.0

Thanks again for your help.

Phil.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/ed94f398-1f34-47b0-862a-4a2cb7b6fa85%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages