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 7034595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:12:19+00:00 2026-05-28T01:12:19+00:00

In my Django website, I have a certain parameter that I would like to

  • 0

In my Django website, I have a certain parameter that I would like to set through url, or query string. E.g. mysite.com/?param=value. I want this value to be passed to all the views once it has been set – I can check it with request.GET.get('param', 'default value'). What would be the easiest way to do that in Django?

To make it more clear, here is an example – in the header of my site I have a dropdown menu with a list of years. Once I click on one of the choices I want this year to be carried over to all the other other parts of my website, i.e. mysite.com/?year=1999, then mysite.com/somethingelse/?year=1999, mysite.com/onemorething/?year=1999 and so on.
Thanks in advance.

  • 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-28T01:12:19+00:00Added an answer on May 28, 2026 at 1:12 am

    One choice is to store this in request.session rather than in request.GET. It would still be set and accessed just as you would want it to be:

    request.session["param"] = "my value"
    
    request.session.get('param', 'default value')
    

    See here for all the details of using sessions.

    The exception would be if you specifically want this in the URL so that it is transparent and the user can change it.

    ETA: Some answers to your questions:

    1. If you really want a ?year=1999 URL to set the session variable in any view, you could create a custom middleware class. Middleware serves as a filter that can alter an HttpRequest before it reaches the view, or alter the HttpResponse that is returning from the view. In this case, you can have it check request.GET and set request.session if necessary, before it then executes the view. See the docs and be sure to read the details about middleware.

    2. Having it in the URL is just not a good idea. There are ways around it but they’re a lot of trouble.

    3. You can use RequestContext to pass a request to a template to be modified there. But why on earth would you do it there instead of in the view function?

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

Sidebar

Related Questions

I have a website built with Django that I would like to combine with
I have a django website that is spilt depending on what user type you
I have a Django applciation running on Apache with mod_wsgi, but I would like
I'm creating a Django powered website that will have numerous applications (Blog, Shop, Portfolio,
I have a Django website that basically just displays a bunch of items from
I have built my website in Django. And like any other django project I
I have a website powered by django. There are few url patterns which i
I have a problems with my django api. I have a website that works
I am looking for displaying Forecast information in my Django Website. Do you have
We have a website made by Django. And there is no problem when access

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.