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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:00:25+00:00 2026-05-12T12:00:25+00:00

Every time I open a page I want to get the currently active project

  • 0

Every time I open a page I want to get the currently active project id. This will be done by chacking the subdomain and verifying the currently logged in user can view it.

Once I reach my view I want to be able to do

tasks = Task.objects.filter(project = current_project)

WHere current_project (or CURRENT_PROJECT or current_project ???) has already been setup.

Can anyone explain the pros/cons of the various approaches I have found in the docs and put me on the right track?

  1. Sessions
  2. Middleware
  3. Threading
  4. builtins

This was how I did it in the end:

Decorator:

def check4project(fn):

    current_project = 'fred'
    def check(*args, **kw):
        kw['project']=current_project
        return fn(*args, **kw)
    return check

View example

@login_required
@check4project
@tweetpost
def index(request, project=0):

    print project
  • 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-12T12:00:25+00:00Added an answer on May 12, 2026 at 12:00 pm

    It all depends on what your semantics of “current project” are. Here are some possibilities:

    1. It could be a characteristic of the user: he visits his profile page and sets a current project. This would be stored in the database, and you would access it with the ORM.

    2. It could be a characteristic of the URL, based solely on subdomain. This could be done with middleware, which has access to the request, and could for example, parse the host name and set a custom attribute on the request that you could access in your view functions.

    3. Similar to #2, you could use a view decorator if checking projects is done for some views but not all. This is similar to Django’s decorators for checking authorization.

    4. It could be a characteristic of the user’s visit to the site: he visits a page of projects, chooses one to work on, and it’s sticky until he chooses another project. This would be best stored in the session, which is specifically for this sort of transient storage.

    From your description, it sounsd like #2 or #3 is the best for you, depending on how your views divide up between caring about subprojects and not.

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

Sidebar

Related Questions

Every second this script will open a page using AJAX and return the contents
Every time I open my Terminal application at work it starts from a clean
I've been using File.ReadAllText() to open a CSV file, but every time I forget
Every time I search in visual studio using CTRL+F - it seems to get
I get the following error in Chrome every time I try to run my
I want to open page [pop up] on page load and my page has
I reload a page every few seconds to get an update from the server,
I want to write some stats to a text file every time a person
My problem is everytime i open the website; first time the map doesn't show
Every time a new developer joins the team or the computer a developer is

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.