title: Wrapping/decorating a function in urls.py vs in views.py
body: <p>So, I'm pretty familiar with wrapping functions in views.py. So I've written a decorator to redirect to the default REDIRECT_URL if the user <em>is</em> logged in (sort of a reverse <code>login_required</code>); it's based on how I've made views in the past:</p>
  
  <pre><code>def not_logged_in(redirect_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
      def decorator(view_func, *args, **kwargs):
          def wrapper(request, *args, **kwargs):
              if not request.user.is_authenticated():
                  return view_func(*args, **kwargs)
              else:
                  redirect_url = (request.REQUEST.get(redirect_field_name, redirect_url) or
                                  settings.REDIRECT_URL)
                  return HttpResponseRedirect(redirect_url)
          return wrapper
      return decorator
  </code></pre>
  
  <p>However, I get the following error: <code>'function' object has no attribute 'status_code'</code> which is caused by a MiddleWare expecting an HttpResponse. When I look at the value for <code>response</code>, I see that it's <code>&lt;function wrapper at 0x2b3a9922a500&gt;</code>.</p>
  
  <p>Here's how I'm calling it in <code>urls.py</code>:</p>
  
  <pre><code>url(r'login/', 
       not_logged_in(auth_views.login), 
       {'authentication_form': LoginForm },
  ),
  </code></pre>