[Flask] flask-android maintain variable between requests

aiman parvaiz aimanparvaiz at gmail.com
Thu Jan 21 15:01:47 EST 2016


Thanks Bryan for this input. I used Flask-Session*
https://pythonhosted.org/Flask-Session/
<https://pythonhosted.org/Flask-Session/>* to implement server side
sessions in Redis. But I am running in to a issue (and this might very well
be my mis understanding of session implementation). When I hit  /activate
endpoint I set the session there as follows:

session[*user_id*] = 'user'

user_id is sent by the app. After setting session here if I do a
session.get(user_id) I get the value back but when I try to the same
thing in          another endpoint /someother

*print session.get(user_id, 'not set')*

I get 'not set'. Now in my understanding if this key was written to
Redis then I should be able to       retrieve it from any endpoint.
Please help   me figure this out if I am missing anything here.

Also in redis-cli when I do a *keys ** I see several
*session:700b4e35-8c5c-4efb-bc6b-1c22b8e29ede, *doing a get on this I
get *(dp1\nS'_permanent'\np2\nI01\ns.* I am assuming this in some
internal implementation of flask sessions but is there a easier way
from the redis-cli to see if   my key is getting set and retrieve its
value?


Thanks


On Sat, Jan 16, 2016 at 7:26 PM, Bryan Corralejo <corralejob at gmail.com>
wrote:

> You could store the data in a session for the user. Flask-session offers
> an interface into  redis/memcached for server side sessions or you can
> store it in a session cookie and have the data sent with every request.
> On Jan 16, 2016 9:16 PM, "aiman parvaiz" <aimanparvaiz at gmail.com> wrote:
>
>> Hi all
>> I am new to flask and am writing API for a simple video upload android
>> app. App uses whatsapp like one time password authentication and the user
>> stays logged in. App has user role and every user has a uuid associated
>> with it. For every end point app sends a uuid to the server and I use that
>> uuid to talk to the DB to get the role of the user. I want to skip this
>> step of going to DB and getting the user role. I wanted to know what would
>> be the best way to get the role from DB once and store it somewhere for all
>> the subsequent user requests till this user logs out. In my limited
>> knowledge flask.g won’t work beyond the first request by the user(As it is
>> valid only for one request) and browser like sessions can’t be supported in
>> the android app(we tried making requests from the app but session['id'] is
>> not available for usage. Same code worked fine on a browser). Should I be
>> looking in to storing a simple key:value in redis/memcahced or is there a
>> better way to approach this issue. Also, I would be using uwsgi and nginx
>> to host this backend.
>>
>> Any help would be appreciated please.
>> Thanks
>>
>> _______________________________________________
>> Flask mailing list
>> Flask at python.org
>> https://mail.python.org/mailman/listinfo/flask
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160121/58640739/attachment.html>


More information about the Flask mailing list