Discuss Sessions, Cookies and Django in the Python Programming forum on Dev Shed. Sessions, Cookies and Django Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 50
Time spent in forums: 8 h 42 m 37 sec
Reputation Power: 4
Sessions, Cookies and Django
I've just come close to finishing off an intranet system for work that I have programmed using Django. I now want to add user login sessions and I've been through the Django documentation to try and learn how to do this. The official docs are useless. I learned Django from them but the 'sessions' part is like another language to me. I understand that Django has session management built in but I can't find a decent tutorial on how to use it.
Basically, all I need is for users to log on before they can use the intranet (preferably leaving a cookie with a unique session id on the client) and then maintain that persons username displayed on each page of the site until they log out or close the browser window.
Do I use Django's own session management (and if so how?) or can I write my own cookie handling system and ignore the Django one? Can anybody point me in the right direction for instructions on creating and using cookies in Django using either method (Django's own or mine)?
Posts: 53
Time spent in forums: 11 h 27 m 28 sec
Reputation Power: 4
Hi,
The Django Book has a chapter on sessions and users and things like that. Its for django 0.96 but i imangine it will still be helpful. You can always debug it if something has changed.
Also if you need more help the google group django users is very helpful for specific issues.
Posts: 50
Time spent in forums: 8 h 42 m 37 sec
Reputation Power: 4
The Django Book appears to be the same as the tutorials on the website. I have scoured the internet for information about cookies and sessions and I understand basic cookie usage now in Python and Django but unfortunately the proper system in Django that you would normally use I still don't understand and the tutorials really are pathetic in this section. The rest of the tutorials are great but I'm sure somebody swallowed a thesaurus when they were writing the session and cookies part.
Posts: 2
Time spent in forums: 29 m 49 sec
Reputation Power: 0
django session management
I'm currently facing the same issue regarding the lack of information on django session management. Did you get some input from other users on how to use django's sesssion management?
The django book is ok in other part but when it come to explain crucial part such as session and user management I believe lacks depth.
Posts: 50
Time spent in forums: 8 h 42 m 37 sec
Reputation Power: 4
I'm gonna get hung for saying this but to be honest I ended up having so much trouble with the sessions and (separately) the database interfacing that I have now switched almost entirely to CherryPy. In CherryPy you get the choice of using their session management or your own and I opted for my own. I also wrote my own database 'interface' which I have managed to quickly convert to Postgresql in light of the current Oracle/Sun issue.
You can use your own session management and database interfacing in Django as well but it was becoming a nightmare for me to avoid issues where Django thought that it knew better about my application and I had to switch off certain settings. As a complete framework Django is not bad, especially if you have the time to learn it on it's own. In my opinion, if you are more of a python programmer than a framework scriptor then I would look at CherryPy or Werkzeug. Sorry I can't help you further with Django.
Posts: 2
Time spent in forums: 29 m 49 sec
Reputation Power: 0
thanks for the feedback.
I'll share your feedback with a Django expert who is currently at some Django forum and find out about such pains before I go too far down the line with Django.
Posts: 1
Time spent in forums: 6 m 9 sec
Reputation Power: 0
Actually I don't see what might confuse you about the way django handles sessions. It's just a object that behaves like a dictionary and it's in every request object if you enable it (add django.contrib.sessions to INSTALLED_APPS and enable the SessionMiddleware). Actually, if all you need is a way for people to log in that is also built in (django.contrib.auth)
What django does with sessions is just making them easier to work with, there's no magic there. You just need to read the docs/django book/code or whatever to learn how things work.
Posts: 50
Time spent in forums: 8 h 42 m 37 sec
Reputation Power: 4
Session management in Django
I started another project with Django. The session tutorial pages on the Django book website had been updated a little since I last posted but the tutorial is not the easiest to understand. As I had already stated, the rest of the guides were pretty clear but this one chapter seemed a bit disorganised and not very clear.
I've actually learned a lot more object-oriented programing in the last few weeks as well and the session management in Django is a bit more understood now but I still stand by my original statement. Session management is easier in CherryPy. It is easy to see how you can build cookies and you have the choice of using them the old CGI way or the CherryPy way. Both are very simple to implement.
To cut down on overhead I am persevering with Djangos session management on this new project but it has not been without it's problems. I just wish it was a damn sight easier to write your own cookies in Django than it is.
Posts: 50
Time spent in forums: 8 h 42 m 37 sec
Reputation Power: 4
Thanks ivo, I keep ending up programming the cookies directly myself. Surprisingly, your explanation works perfectly and is easy to understand in about 1/100th of the number of lines of Djangos docs. I know folks rave about Djangos documentation but I'm starting to feel with a lot of software that unless business/tech like language is used then they are not providing a professional product. Django docs session management section suffers from this.
I do feel bad for some doc authors though because if they get as much as one line of explanation wrong many users complain quite abusively about the error. Having been on the receiving end of this I know what it is like and why I won't produce any more documentation for software.
So, a note to all doc authors.... use simple clear language. Most users will appreciate child-like explanations of software they are unfamiliar with and it is a lot easier to separate tech terms from instructions. Also remember that many users will not speak the native language of the docs.
I have found that FreeBSD's docs is an excellent example of how to write software documentation
..... And a note to users.... if you see an error in some documentation send the author your own explanation of how you interpret things to work, don't complain endlessly about the authors lack of knowledge. If a sheer lack of knowledge is obvious, point the author towards some current docs that may explain a little more to them.... in other words, contribute.
Now that I have a better idea of Djangos session basics I will probably produce a tutorial in the next few weeks after tried a few examples. Feel free to correct and contribute. I'll leave a link on here when it is ready.