gea-sessions + django

35 views
Skip to first unread message

Dilvane

unread,
Feb 15, 2012, 10:23:36 AM2/15/12
to gae-sessions
Hello everyone.

Where can i find a sample of gae-sessions with django?

I did this:

"If you want to gae-sessions with Django, add
'gaesessions.DjangoSessionMiddleware' to your list of
MIDDLEWARE_CLASSES in your settings.py file. You can then access the
session associated with the current request via the request.session
variable. To configure the Django middleware, modify the following
line in gaesessions/__init__.py:

self.wrapped_wsgi_middleware = SessionMiddleware(fake_app,
cookie_key='you MUST change this')"


But didn't work, the session is renewed when i refresh the page.

This give me ever 1:
counter = request.session.get('counter', 0)
request.session['counter'] = counter + 1
print request.session['counter']

Thanks.

David Underhill

unread,
Feb 15, 2012, 1:29:51 PM2/15/12
to gae-se...@googlegroups.com
Hmm, if request.session is set then it seems like the middleware is properly integrated.  You might try putting in some breakpoints and logging statements into the middleware (and perhaps other code) in gaesesssions.py and see what's going wrong.

Dilvane

unread,
Feb 17, 2012, 7:18:48 PM2/17/12
to gae-sessions
David,

I do not know why, but when I remove the "print", it works. :)

I'm thinking to use the gae-sessions in a Rest API to validate users,
do you think is a good idea?

def main(request):
counter = request.session.get('counter', 0)
request.session['counter'] = counter + 1
#print request.session['counter']
return HttpResponse(request.session['counter'])

Thanks.

David Underhill

unread,
Feb 17, 2012, 8:03:05 PM2/17/12
to gae-se...@googlegroups.com
On Fri, Feb 17, 2012 at 16:18, Dilvane <dilvanez...@gmail.com> wrote:
David,

I do not know why, but when I remove the "print", it works. :)

Ah.  When you print to stdout, that starts the HTTP response prematurely.  Avoid writing to stdout directly.  Use logging instead (if that's what you were going for).
 
I'm thinking to use the gae-sessions in a Rest API to validate users,
do you think is a good idea?

Yes, that should work well.

Enjoy,

~ David
Reply all
Reply to author
Forward
0 new messages