sanic/examples/set_sessions.py

20 lines
392 B
Python
Raw Normal View History

2017-08-11 07:00:59 +01:00
# -*- encoding: utf-8 -*-
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route("/")
async def test(request):
if request.session.get('key') is None:
request.session['key'] = 'value'
return json(dict(ok=True))
else:
return json(dict(key=request.session['key']))
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)