# Somewhere in your application:
from registration.forms import RegistrationForm
from django.forms import ValidationError
from django.core.urlresolvers import resolve, Resolver404
from urlparse import urlparse
class NewRegistrationForm(RegistrationForm):
# Ensures than any usernames added will not
# conflict with existing commands.
def clean_username(self):
username = super(NewRegistrationForm, self).clean_username()
try: resolve(urlparse('/' + username + '/')[2])
except Resolver404, e:
return username
raise ValidationError(
(u'This username does not create '
u'a valid URL. Please choose '
u'another'))
# in urls.py:
url(r'^accounts/register/$',
'registration.views.register',
{ 'form_class': NewRegistrationForm },
name = 'registration_register')
Comments