python - How do I extend UserCreationForm to include email field -


i managed stock standard user creation form work. included username, password1 , password2 field. however, when try include email field never shows in template. think i'm missing in view perhaps. here code:

forms.py

from django import forms django.contrib.auth.forms import usercreationform django.contrib.auth.models import user  class usercreationform(usercreationform):     email = forms.emailfield(required=true)      class meta:         model = user         fields = ("username", "email", "password1", "password2")      def save(self, commit=true):         user = super(usercreationform, self).save(commit=false)         user.email = self.cleaned_data["email"]         if commit:             user.save()         return user 

views.py

from django.contrib.auth.forms import usercreationform   def register_user(request): if request.method == 'post':     form = usercreationform(request.post)     if form.is_valid():         form.save()         return httpresponseredirect('/')  args = {} args.update(csrf(request))  args['form'] = usercreationform()  return render_to_response('stories/register.html', args) 

register.html

<form action = "/register/" method = "post">      {% csrf_token %}       <p>     {{ form.username.label_tag }}     {{ form.username}}     </p>      <p>      {{ form.email.label_tag }}     {{ form.email }}     </p>      <p>     {{ form.password1.label_tag }}     {{ form.password1 }}     </p>      <p>     {{ form.password2.label_tag }}     {{ form.password2 }}     </p>      <input type = "submit" value = "register" /> </form> 

all of fields in file being rendered view, except email field.

can spot why?!

you importing wrong usercreationform in views.py. should import own form not django's one:

stories/views.py

from stories.forms import usercreationform ... 

besides that, don't have wrap fields <p></p> individually there exists form.as_p() job.

register.html

<form action = "/register/" method = "post">{% csrf_token %}     {{ form.as_p }} </form> 

hope helps.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -