title: Understanding Django Class-Based (DetailView and View)
body: <p>I'm transitioning some Function-Based Views to Class-Based Views in order to make my views more readable. But I am not understanding quite well the use of <code>DetailView</code> and how I can actually integrate it to my code in order to pass a <code>slug</code> into my function.</p>
  
  <p>For now, I am using <code>View</code> and passing the <code>slug</code> into my function as below:</p>
  
  <pre><code>#urls.py
  path('preview/&lt;slug:slug&gt;/', views.Preview.as_view(), name='toPreview')
  
  #views.py 
  @method_decorator(auth0_login_required, name='dispatch')
  class Preview(View):
      template_name = 'authenticated/preview.html'
  
      @card_is_chosen
      def get(self, slug, request, *args, **kwargs): 
          person = get_object_or_404(Person, slug=slug, status=True)
          ...        
          return render(request, self.template_name, {...})
  </code></pre>
  
  <p><em>I'm am also not quite sure if it's the best practice, in case it is then what does DetailView offer?</em></p>
  
  <hr>
  
  <p><strong>EDIT:</strong> Trying to use DetailView as mentionned in the comments, how can I fix this error ?</p>
  
  <pre><code>#urls.py
  path('preview/&lt;slug:slug&gt;/', views.Preview.as_view(), name='toPreview')
  
  #views.py 
  @method_decorator(auth0_login_required, name='dispatch')
  class Preview(DetailView):
      model = Person
      template_name = 'preview.html'
  
      @card_is_chosen
      def get(self, request, *args, **kwargs): 
          print(slug) 
          #slug is not defined, how should I fetch slug parameter?
          ...
  
          return render(request, self.template_name, {...})
  </code></pre>
  
  <p><strong>Traceback:</strong></p>
  
  <pre><code>File "C:\Users\...\Desktop\env\src\...\apps\businesscards\decorators.py", line 60, in wrap
      return function(self, request, slug, *args, **kwargs)
    File "C:\Users\...\Desktop\env\src\...\apps\businesscards\views.py", line 160, in get
      person = get_object_or_404(Person, slug=slug, status=True)
  NameError: name 'slug' is not defined
  </code></pre>