Using the Django Admin panel without authentication

#django#python

I have some Django projects that I only run locally or have deployed behind a VPN where I am the only user (or admin, at least) so having authentication on the admin panel is unnecessary friction for day-to-day usage.

It’s possible to disable the authentication for the admin panel - but it still requires a user account to be created when making any modifications for auditing purposes.

# urls.py

class AccessUser:
    """
    Fake user object to override permission checking in Django admin to always
    return True
    """

    has_module_perms = has_perm = __getattr__ = lambda s, *a, **kw: True


admin.site.has_permission = lambda r: setattr(r, "user", AccessUser()) or True
Top