title: How to add an attribute to request like the 'user' variable
body: <p>I want to create a new variable which is always available like how the 'user' variable works.</p>
  
  <p>Here is my myapp/context_processors.py</p>
  
  <pre><code>def patient_selected(request):
  
  print(hasattr(request, 'patient_selected_id'))
  print( 'patient_selected_id' in locals())
  print( 'patient_selected_id' in globals())
  
  if not hasattr(request, 'patient_selected_id'):
      request.patient_selected_id = 0
  
  return {"patient_selected_id": 0}
  </code></pre>
  
  <p>The problem is, it always prints 'false'. It seems like I cannot add an attribute to the request, nor create a variable constantly available. 
  BTW, I have added this context_processors.py to settings.
  Here is my setting:</p>
  
  <pre><code>TEMPLATES = [
  {
      'BACKEND': 'django.template.backends.django.DjangoTemplates',
      'DIRS': [],
      'APP_DIRS': True,
      'OPTIONS': {
          'context_processors': [
              'django.template.context_processors.debug',
              'django.template.context_processors.request',
              'django.contrib.auth.context_processors.auth',
              'django.contrib.messages.context_processors.messages',
              'hrs.context_processors.patient_selected',
          ],
      },
  },
  </code></pre>
  
  <p>]</p>
  
  <p>EDIT:
  After reading source codes, it seems like the <code>user</code> variable is not actually created once and live forever. The Middleware and context_processor add a variable <code>user</code> for every request, and this 'user' is actually pulled from session.</p>
  
  <p>My original design is: Once a patient is selected, all following pages will be about this patient. Thus, I would like to make this patient's id always available. Instead of pass this id all around, I want to save it(somewhere) once and always available until another patient is selected. </p>
  
  <p>However now, considering the complexity of <code>user</code> variable, I may give up the fancy way. Simply put this id as a parameter in every request url should be easier.</p>