2016-03-26 7 views

Antwort

1

teilen bin - forms.py:

from registration.forms import RegistrationForm 

class UserProfileRegistrationForm(RegistrationForm): 
    first_name = forms.CharField(max_length=15, label='First name') 
    last_name = forms.CharField(max_length=15, label='Last name') 
    date_of_birth = forms.DateField(label='Date of birth', 
            widget=SelectDateWidget(years=[y for y in range(1950, 
                        datetime.datetime.now().year-17)], 
                  attrs=({'style': 'width: 33%; display: inline-block;'})),) 

    class Meta: 
     model = UserModel() 
     fields = (UsernameField(), "email", 'first_name', 'last_name', 
        'date_of_birth') 

- views.py

from registration.views import RegistrationView 

class UserProfileRegistration(RegistrationView): 
    success_url = '/' 
    form_class = UserProfileRegistrationForm 

    def register(self, form): 
     """ 
     Implement user-registration logic here. 

     """ 

     User = UserModel() 
     user = User.objects.create_user(
      username = form.cleaned_data['username'], 
      first_name = form.cleaned_data['first_name'], 
      last_name = form.cleaned_data['last_name'], 
      email=form.cleaned_data['email'], 
      password=form.cleaned_data['password1'] 
     ) 

Hinweis:, wenn Sie möchte, dass sich der Benutzer automatisch anmeldet: https://djangosnippets.org/snippets/1547/

- urls.py

from myapp.views import UserProfileRegistration 

url(r'^accounts/register/$', UserProfileRegistration.as_view(), name='registration_register'), 
url(r'^accounts/', include('registration.backends.simple.urls')), 

Vielen Dank für DrJackilD. Referenz: https://github.com/macropin/django-registration/issues/73

Verwandte Themen