You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to share session in the child application? #141
The version of official cookbook is still 0.3 but I use the latest 0.61.When I learn how to share session in the child application, the solution given by official cookbook can't work. For example, after I used "session = web.ctx.session" in the child application, it reported an error as "AttributeError: 'ThreadedDict' object has no attribute 'session'" .It just did't share the session at all.
What should I do?
Oh, I have written "session = web.session.Session(app, store, initializer={'login': 0, 'username': ''})" in my parent application. After I modified like you and used 'session.login' in the child application, it reported an error as "AttributeError: 'NoneType' object has no attribute 'login'". So it just means the session I get is None.
Nope. (The previous post was reformatted with ```python and ``` for readability.)
The problem is that the line import child is going to run all code at global scope in client.py. This will mean that the client.py line session = dict(web.ctx).get('session') will get run before the parent.py line web.ctx.session = session
Nope. (The previous post was reformatted with python and for readability.)
The problem is that the line import child is going to run all code at global scope in client.py. This will mean that the client.py line session = dict(web.ctx).get('session') will get run before the parent.py line web.ctx.session = session
Many ways to do it but perhaps the simplest is...
import web
web.config.debug = False
urls = (
'/hello', 'hello'
)
app_child = web.application(urls, globals())
class hello():
def GET(self):
return web.ctx.session.login
AttributeError: 'ThreadedDict' object has no attribute 'session'
No way, I think I just return to initial time! The simplest way you gave is the same as official cookbook.But it's version 0.3,and I use version 0.61.And I have tried the official cookbook twelve hours ago. I need the latest usage!
Activity
cclauss commentedon Aug 3, 2020
Parent:
web.ctx.session = sessionChild:
session = dict(web.ctx).get('session')HackerLZH commentedon Aug 3, 2020
Oh, I have written "session = web.session.Session(app, store, initializer={'login': 0, 'username': ''})" in my parent application. After I modified like you and used 'session.login' in the child application, it reported an error as "AttributeError: 'NoneType' object has no attribute 'login'". So it just means the session I get is None.
cclauss commentedon Aug 3, 2020
Let's use assertions to see where the problem lies...
Parent:
Child:
HackerLZH commentedon Aug 3, 2020
Traceback (most recent call last):
File "D:/Python/web.py/main.py", line 3, in
import enter
File "D:\Python\web.py\enter.py", line 23, in
assert session, "Invalid session provided."
AssertionError: Invalid session provided.
Ok, Invaid session provided
cclauss commentedon Aug 3, 2020
Are we sure that the parent lines have already been run?
HackerLZH commentedon Aug 3, 2020
Something like that!
cclauss commentedon Aug 3, 2020
Nope. (The previous post was reformatted with ```python and ``` for readability.)
The problem is that the line
import childis going to run all code at global scope inclient.py. This will mean that the client.py linesession = dict(web.ctx).get('session')will get run before the parent.py lineweb.ctx.session = sessionHackerLZH commentedon Aug 3, 2020
So that's it, how can I run after the parent.py?
cclauss commentedon Aug 3, 2020
Many ways to do it but perhaps the simplest is...
HackerLZH commentedon Aug 3, 2020
AttributeError: 'ThreadedDict' object has no attribute 'session'
No way, I think I just return to initial time! The simplest way you gave is the same as official cookbook.But it's version 0.3,and I use version 0.61.And I have tried the official cookbook twelve hours ago. I need the latest usage!
HackerLZH commentedon Aug 4, 2020
I use python38, not python2