Questions tagged [django-sessions]

For questions related to Django's session mechanism.

Django provides full support for anonymous sessions. The session framework lets you store and retrieve arbitrary data on a per-site-visitor basis. It stores data on the server side and abstracts the sending and receiving of cookies. Cookies contain a session ID – not the data itself (unless you’re using the cookie based backend or a custom backend).

Reference: https://docs.djangoproject.com/en/stable/topics/http/sessions/

490 questions
0
votes
1 answer

Getting username in Django on every single page regardless of how I got there

This is more theory question than specific code problem. I'm kinda confused how information like username, user email, etc. is stored and accessed in Django. From what I know: I can access it like {{user.username}} IF previously I got here by using…
0
votes
1 answer

Use Django sessions per view as opposed to per user

I am confused! I am trying to use Django's caching system to store some data so that it is accessible throughout the GET/PUT of the main view as well as several potential AJAX views while the user is interacting w/ the page. I thought that I would…
trubliphone
  • 4,132
  • 3
  • 42
  • 66
0
votes
0 answers

Unused Django sessions not expiring, cluttering database

One of my Django websites was recently found by some crawler that went nuts over the login page, requesting it 100-200 times per minute for a couple days before I noticed. I only found out because my database backups started exploding in size,…
Nick T
  • 25,754
  • 12
  • 83
  • 121
0
votes
1 answer

accessing dict values from request.session in views

I'm trying to obtain a session variable within a view but I'm not having much luck. The error I'm receiving is: list indices must be integers, not str I have the following session variable/dict being set: u'bookingContents' : { …
AndrewO
  • 1,105
  • 4
  • 16
  • 33
0
votes
3 answers

Current field values from session in Django

I'm building a django web app to allow customers to sign up for courses. On the page "training" all courses are listed. The users clicks on a course to get more details and apply for that course. The course model looks like this: class…
Oliver Burdekin
  • 1,098
  • 2
  • 17
  • 36
0
votes
2 answers

Django REST API Logout request

For logging in, I'm doing something like: function setHeader(xhr) { // as per HTTP authentication spec [2], credentials must be // encoded in base64. Lets use window.btoa [3] xhr.setRequestHeader("Authorization", "Basic " +…
0
votes
1 answer

Accessing session expiry date in Django template

I'm setting the session value for a variable in my as follows request.session['a'] = True request.session.set_expiry(604800) If I access the session in my template as follows, it shows it's value {{ request.session.a }} How can I get the session…
Yin Yang
  • 1,776
  • 3
  • 26
  • 48
0
votes
1 answer

Funny Django Session Behaviour

In my settings.py I have SESSION_EXPIRE_AT_BROWSER_CLOSE = True. I am not sure if that is the right place to do that and if need to import anything first. But it wasn't working on Chrome Version 37.0.2062.124 m as it persists the session data. My…
Yax
  • 2,127
  • 5
  • 27
  • 53
0
votes
2 answers

Renew session_key django

I am try to write a function that gets the username of the person logged and right after that changes de session_key into a new one. What I have written so far is this: def get_username(request): try: for coisa in request: …
user2449798
  • 434
  • 1
  • 5
  • 13
0
votes
1 answer

Using python sessions to pass variable from one function to another function

I have a couple of quick questions - ~* when I used to code in Java, we used to reduce the usage of session variables as it used to slow the engine/occupy quite some space. In Python-django when I was trying to access one variable in two functions I…
Krishna Teja Karnam
  • 133
  • 1
  • 3
  • 14
0
votes
1 answer

Django, track session even as user logs in and out

How do I track sessions in Django even after a user has logged in or out? I am using Django authentication. For example, a user lands on the main page, and maybe follows a few links on my site. Then he logs in. Logs out. Follows some links. I want…
user984003
  • 28,050
  • 64
  • 189
  • 285
0
votes
1 answer

Using Django session key to use request sessions between views

Is it a good idea to store django _session_key in another model as an identifier for specific session. I am using django _session_key to store a unique session inside a view and then I am saving the _session_key in another object . def…
Ayush
  • 167
  • 3
  • 10
0
votes
0 answers

How can I get the first item out of a session list in django?

For example, I set request.session['jump'] = [u'howhigh',u'justlow'] ( i did this by getting values from a form) How can I get just the first value? I thought something like jump = request.session['jump'][0] would work, but its ont doing it for…
user3525985
  • 109
  • 7
0
votes
3 answers

A few basic django questions

I am a newbie in django, and I need some examples on this code I am working on. I have a textbox, and an output on the same template and this is the view for this: def sessiontest(request): a=request.session.get('a',{}) form=sform() …
user2478240
  • 369
  • 3
  • 15
0
votes
1 answer

Django sessions keeps returning 'NoneType' error

I am currently using Django forms to have users enter information, which I then use Django sessions to call in other view functions in my views.py file. Currently my form is processed in the view function, 'search' and is called using sessions in…
ng150716
  • 2,195
  • 5
  • 40
  • 61