Stephen Gilmore

🐍 Disable django-allauth signups

Django August 29th, 2022 1 minute read.

Django-allauth comes with a bunch of useful features. But what if I wanted to disable signups? Thank you getup8 on stackoverflow for the answer

In the same folder as the project settings.py create a file named account_adapter.py. The contents of this file will be:

# project_name/account_adapter.py
from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter

class CustomAccountAdapter(DefaultAccountAdapter):
    def is_open_for_signup(self, request):
        """
        Whether to allow sign ups.
        """
        allow_signups = super(CustomAccountAdapter, self).is_open_for_signup(request)
        # Override with setting, otherwise default to super.
        return getattr(settings, "ACCOUNT_ALLOW_SIGNUPS", allow_signups)

And then in the settings.py file we'll add:

# project_name/settings.py
ACCOUNT_ALLOW_SIGNUPS = False
ACCOUNT_ADAPTER = "django_project.account_adapter.CustomAccountAdapter"

After completing these steps, whenever someone tries to visit example.com/account/signup they will be directed to a templates/account/signup_closed.html template.