djangosnippets.org: Latest snippets posted by mjumbehttps://djangosnippets.org/users/mjumbe/2011-07-25T02:25:15.007512-05:00mjumbeLoginRequired class-based view decorator
2011-07-25T02:25:15.007512-05:00mjumbehttps://djangosnippets.org/snippets/2495/<p>Apply the <code>login_required</code> decorator to all the handlers in a class-based view that delegate to <code>cls.dispatch</code>.</p>
<p>Optional arguments:</p>
<ul>
<li>redirect_field_name = <code>REDIRECT_FIELD_NAME</code></li>
<li>login_url = <code>None</code></li>
</ul>
<p>See the documentation for the <a href="https://docs.djangoproject.com/en/dev/topics/auth/#the-login-required-decorator"><code>login_required</code></a> method for more information about the keyword arguments.</p>
<p>Usage:</p>
<pre><code>@LoginRequired
class MyListView (ListView):
...
</code></pre>
Freely redistributable