LPTHW ex25运行Web应用报错:module 'web' has no attribute 'config_session'
Fix AttributeError: module 'web' has no attribute 'config_session' in LPTHW ex25 Web App
The error you're hitting is caused by a straightforward typo in your app.py code. Let's break down the issue and fix it:
Root Cause
Look at the session initialization section of your code:
if web.config.get('_session')is None: store=web.session.DiskStore('sessions') session=web.session.Session(app,store,initializer={'room':None}) web.config._session=session else: session=web.config_session # This line has the mistake!
You tried to access web.config_session, but the correct attribute is web.config._session (note the underscore between config and _session). The web.config object holds the _session attribute you set earlier, so you need to use dot notation to access it properly.
Fixed Code
Update that section to this corrected version:
if web.config.get('_session') is None: store = web.session.DiskStore('sessions') session = web.session.Session(app, store, initializer={'room': None}) web.config._session = session else: session = web.config._session # Corrected attribute access
Next Steps After Fix
- Re-run your app with
python3 bin/app.py - Visit
http://0.0.0.0:8080/– it should now redirect to/gameand load the starting room without errors - As a side note, you might want to address the commented "bug here" in your
POSTmethod: currently, ifform.actionis an empty string,session.roomwill be set toNone. Adjusting the condition toif session.room and form.action is not None and form.action:would handle empty input better, but that's a separate improvement for later.
内容的提问来源于stack exchange,提问作者Poppy Bee
相关产品推荐
相关产品推荐

