Skip to content
Get inside your stronghold and make all your Django views default login_required
Python Makefile
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

django-stronghold - Get inside your stronghold and make all your Django views default login_required

Stronghold is a very small and easy to use django app that makes all your Django project default to require login for all of your views.


Install via pip.

pip install django-stronghold

Add stronghold to your INSTALLED_APPS in your Django settings file


Then add the stronghold middleware to your MIDDLEWARE_CLASSES in your Django settings file



If you followed the installation instructions now all your views are defaulting to require a login. To make a view public again you can use the public decorator provided in stronghold.decorators like so:

For function based views

from stronghold.decorators import public

def someview(request):
    # do some work

for class based views

from django.utils.decorators import method_decorator
from stronghold.decorators import public

class SomeView(View):
    def get(self, request, *args, **kwargs):
        # some view logic

    def dispatch(self, *args, **kwargs):
        return super(SomeView, self).dispatch(*args, **kwargs)

Configuration (optional)

You can add a tuple pf public url regexes in your settings file with the STRONGHOLD_PUBLIC_URLS setting.

Default setting when debug == False :


Default setting when debug == True :

STRONGHOLD_PUBLIC_URLS = (r'^/static/.+$', r'^/media/.+$')



Something went wrong with that request. Please try again.