Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3941990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:36:33+00:00 2026-05-20T00:36:33+00:00

When using Django sessions , is it good practice to see if session data

  • 0

When using Django sessions, is it good practice to see if session data has been previously set, and if not to set the initial session data, in the same view?

Will this cause major issues, for me or users, if users have their cookies disabled?

(The presence of test cookies has confused me a little. However if you used these you would not be able to record data about the page the user initially viewed.)

Below is an excerpt from my views.py file. In the view the user is visiting a page with a game on it.

If they have previously stored session data – and if first time viewing game – the view will modify session data to record the fact they have visited game. If they have no session data it will be initialised here for them.

def game(request, game_name):
    game = get_object_or_404(Game, web_name=game_name)
    c = { 'game': game }

    # game_votes is used to store if user has voted on game yet.
    # Also a key in dictionary indicates user has previously visited that game.
    game_votes = request.session.get('game_votes', False):
    if game_votes:
        if not game_votes.has_key(game_name):
            game_votes[game_name] = False
            request.session['game_votes'] = game_votes
            request.session.modified = True
        else:
            pass
    else: # I.e. no session was declared previously.
        request.session['game_votes'] = { game_name: False }
        request.session['sorting_choice'] = 'PO'
        request.session['ip_address'] = request.META['HTTP_X_FORWARDED_FOR']

    return render_to_response('game.html', c)

As this is the first time I’ve used Django, I wanted to know what glaring mistakes I have inadvertently made with regards to using sessions.

Thank you very much for your expertise and help 🙂

EDIT:

So just to check: if a user has cookies disabled, this doesn’t create a new session entry in the database for every page he views? Right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:36:33+00:00Added an answer on May 20, 2026 at 12:36 am

    This is exactly right. Session data isn’t stored in cookies – the cookie just stores the unique ID of the user’s data in the session database.

    One minor nit: don’t use has_key – it has been discouraged in Python for years. Use in:

    if game_name in game_votes:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am evaluating using CouchDB in my new Django-project. Is there a good database
I've been using rails, merb, django and asp.net mvc applications in the past. What
I'm using Django to send an e-mail which has a text part, and an
I've been using django-mptt in my project for a while now, it's fabulous. Recently,
I'm using django and jquery to implement authenticated sessions and Ajax requests. I have
I'm using sessions in Django to store login user information as well as some
In my django app I was creating an extended user profile using session vars.
Using Django's built in models, how would one create a triple-join between three models.
I'm considering using Django for a project I'm starting (fyi, a browser-based game) and
I'm using Django to write a blog app, and I'm trying to implement a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.