I use Python 3 as a serverside scripting language, and I want a way to keep users logged into my site. I don't use any framework, since I prefer to hand code pages, so how do I create session variables like in PHP in Python 3?
-
4Normally that's handled by the framework. If you're using custom code, it will depend entirely on how your code is set up to do it (so honestly, you may be the only person who can answer your own question).David Z– David Z2012-04-15 21:46:27 +00:00Commented Apr 15, 2012 at 21:46
-
8You really shouldn't use CGI. Use a nice framework such as flask and run it via WSGI. And the NIH syndrome is a very bad thing!ThiefMaster– ThiefMaster2012-04-15 21:49:38 +00:00Commented Apr 15, 2012 at 21:49
-
5Your questions probably should be: "I'm writing my own web framework in Python. Here's how I'm trying to do session variables and it doesn't work. How can I fix it?"alan– alan2012-04-15 21:53:01 +00:00Commented Apr 15, 2012 at 21:53
-
1Sounds like you are really building your own framework. That's cool, but you should try to build on the work of others because life is too short for everyone to repeat the same mistakesJohn La Rooy– John La Rooy2012-04-15 23:42:01 +00:00Commented Apr 15, 2012 at 23:42
Add a comment
|
1 Answer
The logic of a session is storing a unique session id inside the user cookie ( uuid package will do a perfect job for that ). And you store the sessions data inside a file, database or other semi-permanent datastore.
The idea is matching the sessionid that you receive from your user cookie, to some data stored somewhere on your server.
I assume that you know how to add the right header to set a cookie via the response header. Otherwise there is more information here : http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Responses