from flask import Flask,redirect
from flask import session
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/signup', methods = ['POST'])
def signup():
email = 'xxxx'
session['email'] = email
print session['email']
print("The email address is '" + email + "'")
return redirect('/')
@app.route('/unregister', methods = ['POST'])
def unregister():
print "session check"
print session['email']
return 'We have removed from the list!'
if __name__ == '__main__':
app.secret_key = '#d\xe9X\x00\xbe~Uq\xebX\xae\x81\x1fs\t\xb4\x99\xa3\x87\xe6.\xd1_'
app.debug = True
app.run()
私がこれを実行すると、http://127.0.0.1:5000/でサーバーを実行できます。私が直面している問題は、session
をsignup
に使用できますが、unregister
では使用できないということです。私はカールによってそれを使用しています:Pythonフラスコのマイクロフレームワークでセッション変数を使用できない
curl -X POST http://127.0.0.1:5000/unregister
私はこのエラーを参照してください。
127.0.0.1 - - [07/Apr/2016 16:06:08] "POST /unregister HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ,
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1820, in
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1403, in
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/pvelumul/ACI/workspace/acitoolkit/applications/snapback/helloworld.py", line 20, in unregister
print session['email']
File "/usr/local/lib/python2.7/site-packages/Werkzeug-0.11.4-py2.7.egg/werkzeug/local.py", line 373, in <lambda>
__getitem__ = lambda x, i: x._get_current_object()[i]
KeyError: 'email'