title: Is it okay to set instance variables in a Django class based view?
body: <p>I trying out Django's class based views (CBVs).</p>
  
  <pre><code>class BlahView(TemplateView):
      template_name = 'blah/blah.html'
      def get_context_data(self, **kwargs):
          #code...
  
      def get(self, request, **kwargs):
          #more code...
  </code></pre>
  
  <p>Now, I know that I can get the request params from self.request. Now say I want to parse these request params and store them within the class. Can I store those in <code>self.xxx</code>? Now, obviously based on how classes work, this seems straightforward.</p>
  
  <p>But I can't make out the flow of control, looking at the definition of <code>View</code> (superclass of <code>TemplateView</code>). The <a href="https://github.com/django/django/blob/master/django/views/generic/base.py" rel="noreferrer">source</a> mentions <code>as_view()</code> to be the 'entry-point'</p>
  
  <p>I thought of setting my instance variables at the beginning of <code>get_context_data()</code> but that doesn't seem right to do initialization there.</p>
  
  <p>Can I define an <code>__init__()</code> for my CBV?
  If so, will there be threading issues or something where multiple page-accesses possibly work with a global instance of my parsed data?</p>
  
  <p>I know this sounds a bit messy, but I'm just a bit confused with the code flow in CBVs.</p>