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

  • SEARCH
  • Home
  • 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 6112219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:43:13+00:00 2026-05-23T14:43:13+00:00

I have a Django website that basically just displays a bunch of items from

  • 0

I have a Django website that basically just displays a bunch of items
from a database with searching, filtering, etc. The site is publicly
accessible, with no login or anything. What I want to do is the first
time a user visits the site, prompt them for a filter choice, then
save that filter choice (on their machine would be preferable, would a
browser cookie work here?) so that every future time they visit the
website, it’s displayed with that filter.

So I have two specific questions here:

1) What’s the best way to store their choice?

2) What’s the best way to collect their choice? The way I’m
envisioning this behaving is the first time they visit the site,
they’re presented with a “pop-up” of sorts, that basically asks for
their filter choice, the continues on to the main site page with their
filter choice enabled. The problem I’m having is that the filter
choice that they pick changes the content that would be displayed on
the website. Is there a way to avoid reloading the entire page once I
have their filter choice?

Here’s a decent example of something like the popup I’m trying to
create: http://www.wizards.com/wpn/events/rules.aspx

Thanks,
-Alexei

  • 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-23T14:43:13+00:00Added an answer on May 23, 2026 at 2:43 pm

    Giving a cookie to the user would definitely work. In web development the technique is known as creating a ‘session’ for the user so that every time they request a page from your site, the request can be identified as part of that particular session and serviced accordingly.

    Django ships with an excellent and very easy to use sessions framework. You should read the documentation here, but I will summarise the steps you’ll need to take.

    1. Enable the Django sessions middleware (this is already done in the default Django project). Make sure django.contrib.sessions.middleware.SessionMiddleware is in your MIDDLEWARE_CLASSES variable in the settings file.
    2. Choose a sessions backend. Database sessions will work well enough to begin with (if performance becomes a problem later, consider cached sessions with Memcached providing storage).
    3. Set an appropriate SESSION_COOKIE_AGE that meets your requirements. You can set this number very high if you want users’ choices to last for a long time.

    Once you’ve done this, the request variable that is passed into your views will have a session attribute. session is an object which you can use like a dictionary to store information. The magic bit is that that information will be unique to every user who makes requests to your site.

    This partial code demonstrates how to return content based on a previously selected user choice stored in their session:

    def get_front_page_contents(request):
        filter = request.session.get('filter_choice', False)
        if filter:
            # do the filtering 
            render_to_response(template_name,
                {'filtered_content': content},
                RequestContext(request))
        else:
            # the user has not made a choice so
            # return a default result set or redirect 
            # to form that allows them to make a choice
    

    Your second question was how to collect this choice in the first place. Here’s a simple solution that uses multiple page loads.

    1. On initial request to the home page, check whether the request.session has a choice saved for this user.
      • If they do, render a page containing filtered content (and you’re done).
      • If not, redirect to a form where they can make a choice.
    2. On form submission, store the choice in request.session for this user. Return their desired content.

    After this process, when the same user comes back to step one at a later date, their desired content would be displayed.

    Avoiding page reloads is a separate issue, but it’s easily done with javascript and AJAX techniques. You’ll probably want to serve a minimal page which includes javascript to make the requests for content. These AJAX requests can be examined in exactly the same way to check for the presence of session data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in a django based website that displays the content
we have just started using a git account of our Django website project so
I have a website that is being served by nginx and django. My staging.py
I have a rather simple informational website that's being run by Django. Its' pages(views)
I have a django website that is spilt depending on what user type you
I'm creating a Django powered website that will have numerous applications (Blog, Shop, Portfolio,
I have a django project which runs just fine with runserver located in: D:\EverTabs\work\evertabs-website\src\evertabs\
I have a Django website that requires users to be logged in to view
I have Django app that presents a list of items that you can add
I have a Django website where I'm using some of the forms from the

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.