Custom Form Validation in Django-Allauth

后端 未结 1 1977
再見小時候
再見小時候 2021-01-12 12:03

I want to do some extra validation on fields in django-allauth. For example I want to prevent using free email addresses. So I want to run this method on signup

<         


        
相关标签:
1条回答
  • 2021-01-12 12:40

    There are some adapters on the allauth configuration. For example this one:

    ACCOUNT_ADAPTER (="allauth.account.adapter.DefaultAccountAdapter")
        Specifies the adapter class to use, allowing you to alter certain default behaviour.
    

    You can specify a new adapter by overriding the default one. Just override the clean_email method.

    class MyCoolAdapter(DefaultAccountAdapter):
    
        def clean_email(self, email):
            """
            Validates an email value. You can hook into this if you want to
            (dynamically) restrict what email addresses can be chosen.
            """
            *** here goes your code ***
            return email
    

    Then modify the ACCOUNT_ADAPTER on the settings.py

    ACCOUNT_ADAPTER = '**app**.MyCoolAdapter'
    

    Check the default behavior on: https://github.com/pennersr/django-allauth/blob/master/allauth/account/adapter.py

    0 讨论(0)
提交回复
热议问题