title: Function to Class Based View (DetailView) Django
body: <p>So my function-base view currently looks like this, and I would like to change it to Class Based View</p>
  
  <p>My Function View </p>
  
  <pre><code>def user_detail(request, username):
      try:
         user = User.objects.get(username=username)
      except User.DoesNotExist:
         raise Http404
  </code></pre>
  
  <p>My Class Based View</p>
  
  <pre><code>class UserProfileDetail(DetailView):
      model = User
      template_name = "profiles/user_detail.html"
      #use username instead of pk
      slug_field = "username"
  </code></pre>
  
  <p>My url</p>
  
  <pre><code>url(r"^user/(?P&lt;slug&gt;[\w-]+)/$", UserProfileDetail.as_view(), name="user_detail"),
  </code></pre>
  
  <p>The Problem is, when I go to the <a href="http://exampe.com/user/username" rel="nofollow">http://exampe.com/user/username</a> url, I get the Anonymous user profile. I don't want that. What changes do I have to make on my UserProfileDetail class?</p>
  
  <p>thank you in advance</p>