I create registration form:
#urls.py
from django.conf.urls import patterns, url
from django.views.generic import TemplateView
from account.views import Register
urlpatterns = patterns('',
url(r'^register/$', Register.as_view(template_name='account/register.html')),
)
#views.py
from django.views.generic import CreateView
from django.contrib.auth.models import User
class Register(CreateView):
model = User
success_url = '/account/'
And i have question: how I can add that email be require (now I must only enter username, password and 2 times time).
@edit
And how “repair” password? When i create user (in this form) and then go to admin panel, in user i see “Invalid password format or unknown hashing algorithm.”. How i can repair this?
The reason that email is not required is because you’re using a
ModelForm, which takes a lot of cues from the underlyingUsermodel. Specifically, therequired=Trueattribute is not present on theemailfield of the model.One solution is to create your own form with the necessary attributes, perhaps by using a ModelForm and adding a required email field.
Another solution, and probably the better one, is to use something like django-registration as mentioned by Aamir Adnan in the comments to your question. It’ll simplify things a lot for you.
As far as your
repair passwordgoes, you can’t set the password to a raw string value as you’re doing with yourCreateView. To set a password, you have to calluser.set_password(raw_string)which will take care of hashing and salting for you. Look how the built in UserCreationForm works, and try to mimic it if you decide to build the form yourself, rather than using a library (you shouldn’t).