title: Should a database connection be opened only once in a django app or once for every user within views.py?
body: <p>I'm working on my first Django project.</p>
  
  <p>I need to connect to a pre-existing key value store (in this case it is Kyoto Tycoon) for a one off task. i.e. I am not talking about the main database used by django.</p>
  
  <p>Currently, I have something that works, but I don't know if what I'm doing is sensible/optimal.</p>
  
  <p>views.py</p>
  
  <pre><code>from django.http import HttpResponse
  from pykt import KyotoTycoon
  
  def get_from_kv(user_input):
  
      kt=KyotoTycoon()
      kt.open('127.0.0.1',1978)
  
      # some code to define the required key
      # my_key = ...
  
      my_value = kt.get(my_key)
  
      kt.close()
  
      return HttpResponse(my_value)
  </code></pre>
  
  <p>i.e. it opens a new connection to the database every time a user makes a query, then closes the connection again after it has finished.</p>
  
  <p>Or, would something like this be better?</p>
  
  <p>views.py</p>
  
  <pre><code>from django.http import HttpResponse
  from pykt import KyotoTycoon
  
  kt=KyotoTycoon()
  kt.open('127.0.0.1',1978)
  
  def get_from_kv(user_input):
  
      # some code to define the required key
      # my_key = ...
  
      my_value = kt.get(my_key)
  
      return HttpResponse(my_value)
  </code></pre>
  
  <p>In the second approach, will Django only open the connection once when the app is first started? i.e. will all users share the same connection?</p>
  
  <p>Which approach is best?</p>