我在web應用中使用webapp2進行請求處理,爲模板添加django,在我的項目中添加了webapp2會話。'webapp2_extras.sessions'缺失配置鍵:['secret_key']
繼this page,我添加了下面給我的腳本
import webapp2
from webapp2_extras import sessions
class BaseHandler(webapp2.RequestHandler):
def dispatch(self):
# Get a session store for this request.
self.session_store = sessions.get_store(request=self.request)
try:
# Dispatch the request.
webapp2.RequestHandler.dispatch(self)
finally:
# Save all sessions.
self.session_store.save_sessions(self.response)
@webapp2.cached_property
def session(self):
# Returns a session using the default cookie key.
return self.session_store.get_session()
config = {}
config['webapp2_extras.sessions'] = {
'secret_key': 'my-super-secret-key',
}
不過,現在我得到以下錯誤
Traceback (most recent call last):
File "/home/user/google_appengine/lib/webapp2/webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "/home/user/google_appengine/lib/webapp2/webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "/home/user/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/user/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/home/user/sites/project2n/main.py", line 804, in dispatch
self.session_store = sessions.get_store(request=self.request)
File "/home/user/google_appengine/lib/webapp2/webapp2_extras/sessions.py", line 454, in get_store
store = request.registry[key] = factory(request)
File "/home/user/google_appengine/lib/webapp2/webapp2_extras/sessions.py", line 308, in __init__
required_keys=('secret_key',))
File "/home/user/google_appengine/lib/webapp2/webapp2.py", line 1361, in load_config
self._validate_required(key, config, required_keys)
File "/home/user/google_appengine/lib/webapp2/webapp2.py", line 1375, in _validate_required
'Missing configuration keys for %r: %r.' % (key, missing))
Exception: Missing configuration keys for 'webapp2_extras.sessions': ['secret_key']
我已經設置了密鑰,使用config。我沒有使用任何其他會議。其他進口
import os,sys, string, time, sha, Cookie
from django.template import Context, Template
from django.template.loader import get_template
我掩蓋了這一細節,添加config = config清除了問題。 – abel
沒有StackOverflow.Lol,生活就沒有意義了。這個問題讓我發瘋。 –