Not able to add custom fields to django-registration

前端 未结 3 1287
逝去的感伤
逝去的感伤 2020-12-10 22:44

I extended RegistrationFormUniqueEmail

class CustomRegistrationFormUniqueEmail(RegistrationFormUniqueEmail):
    first_name = forms.CharField(la         


        
相关标签:
3条回答
  • 2020-12-10 23:14

    We recently implemented such a form. Here's what we've done:

    • Create a new backend (just copy it from the default backend to start with)

      registration/
          backends/
              default/
              custom/ # <- your new backend
      

      ...

    • In the new urls.py adjust the backend arguments

      ...
      { 'backend': 'registration.backends.custom.DefaultBackend' },
      ...
      
    • Create a forms.py under custom. Adjust this form to your liking (fields and validations)

    • In the registration/urls.py point to the proper backend:

       # from registration.backends.default.urls import *
       from registration.backends.custom.urls import *
      

    That should work. Particularly this works because:

    • Your custom/__init__.py will have a DefaultBackend class with a get_form_class method:

      def get_form_class(self, request):
          """
          Return the default form class used for user registration.
          """
          return RegistrationForm
      
    • And you import your own RegistrationForm in that file, too:

      from registration.backends.custom.forms import RegistrationForm
      
    0 讨论(0)
  • 2020-12-10 23:15

    I'm not sure, off hand, why it isn't working but I am pretty sure you do not need to edit django-registration's views.py ... you can pass your new CustomRegistrationFormUniqueEmail as an argument in urls.py.

    0 讨论(0)
  • 2020-12-10 23:21

    You can try to look here Extending django-registration using signals and here http://dmitko.ru/?p=546

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