Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Dear fellow Django Coder,</p> <p>I think this is the best way to do it. Good luck!</p> <p><em>First step, is to create the form you'd like to use</em>.</p> <p><strong>project/accounts/forms.py</strong></p> <pre><code>from django import forms from registration.forms import RegistrationForm from django.contrib.auth.models import User class Email(forms.EmailField): def clean(self, value): super(Email, self).clean(value) try: User.objects.get(email=value) raise forms.ValidationError("This email is already registered. Use the 'forgot password' link on the login page") except User.DoesNotExist: return value class UserRegistrationForm(forms.Form): password1 = forms.CharField(widget=forms.PasswordInput(), label="Password") password2 = forms.CharField(widget=forms.PasswordInput(), label="Repeat your password") #email will be become username email = Email() def clean_password(self): if self.data['password1'] != self.data['password2']: raise forms.ValidationError('Passwords are not the same') return self.data['password1'] </code></pre> <p><em>Here you are creating a file to override the register() function in django-registration.</em> </p> <p><strong>project/accounts/regbackend.py</strong></p> <pre><code>from django.conf import settings from django.contrib.sites.models import RequestSite from django.contrib.sites.models import Site from registration import signals from registration.forms import RegistrationForm from registration.models import RegistrationProfile from registration.backends import default class Backend(default.DefaultBackend): def register(self, request, **kwargs): email, password = kwargs['email'], kwargs['password1'] username = email if Site._meta.installed: site = Site.objects.get_current() else: site = RequestSite(request) new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site) signals.user_registered.send(sender=self.__class__, user=new_user, request=request) return new_user </code></pre> <p><em>Direct your urls to paths you want to use.</em></p> <p><strong>project/urls.py</strong></p> <pre><code>(r'^accounts/', include('registration.backends.default.urls')), </code></pre> <p><em>Tell your urls to use the custom backend for the registration view. Also, import the form you created and add it to the url to be processed by the view.</em></p> <p><strong>project/accounts/urls.py</strong></p> <pre><code>from django.conf.urls.defaults import * from registration.backends.default.urls import * from accounts.forms import UserRegistrationForm urlpatterns += patterns('', #customize user registration form url(r'^register/$', 'registration.views.register', { 'backend': 'accounts.regbackend.Backend', 'form_class' : UserRegistrationForm }, name='registration_register' ), ) </code></pre> <p>Hope that works!</p> <p>-Matt</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload