<p>I'm about to put a beta version of the site I'm working on up on the web. It needs to have a beta code to restrict access. The site is written in django.</p>

<p>I don't want to change the fundamental Auth system to accommodate a beta code, and I don't care particularly that the security of the beta code is iron-clad, just that it's a significant stumbling block.</p>

<p>How should I do this? It's a fairly large project, so adding code to every view is far from ideal.</p>

<hr>

<p>That solution works well. The Middleware Class I ended up with this this:</p>

<pre><code>from django.http import HttpResponseRedirect

class BetaMiddleware(object):
    """
    Require beta code session key in order to view any page.
    """
    def process_request(self, request):
        if request.path != '/beta/' and not request.session.get('in_beta'):
            return HttpResponseRedirect('%s?next=%s' % ('/beta/', request.path))
</code></pre>

You should be able to add
```
@login_required
```
decorators across the board and be done with it.  Unless you have a boat-load of view functions, it shouldn't be too horrible.