tags:

views:

24

answers:

2

For a project I'm working on, we're still undecided whether the site will launch on an invite-only basis, or be open to the general public immediately. Notwithstanding the management of invites, how would one go about to render a public site invite-only in Django?

One way I can come up with is adding @login_required to all views, but that seems to be too labour intensive... In other words, is there a way to restrict the use of the site to those who have login credentials in one swoop?

Thanks in advance!

A: 

Perhaps you could use signals to catch people that are not logged in:

http://docs.djangoproject.com/en/dev/ref/signals/#django.core.signals.request_started

Or you could fiddle with the urlpatterns somehow, so that the urlpatterns list only contains the required login stuff when you're not logged in. That would work, right?

André Laszlo
+1  A: 

Have you looked at the privatebeta application (PyPI, GitHub)? It seems like that does what you are looking for. Otherwise you can at least have a look at their middleware component to base your code on.

Mark van Lent
There's an interesting link - I should remember to check github more often... Anyway, I see they're restricting access through middleware, which is of course the perfect way to do this. Thanks for the pointer!
LaundroMat