python - Django: name 'SignupFormExtra' is not defined -
i have django-userena installed , trying override default sign form custom 1 can have fields, being new django, happen stuck. after following guide documentation userena have app called accounts. in app created 'forms.py' , put following info:
from django import forms django.utils.translation import ugettext_lazy _ userena.forms import signupform class signupformextra(signupform): """ form demonstrate how add fields signup form, in case adding first , last name. """ first_name = forms.charfield(label=_(u'first name'), max_length=30, required=true) last_name = forms.charfield(label=_(u'last name'), max_length=30, required=true) industry = forms.charfield(label=_(u'industry'), max_length=50, required=false) occupation = forms.charfield(label=_(u'occupation'), max_length=50, required=false) bio = forms.textfield(label=_(u'bio'), required=true) skills = forms.textfield(label=_(u'skills'), required=false) interests = forms.textfield(label=_(u'interests'), max_length=50, required=false) phone = forms.charfield(label=_(u'phone'), max_length=10, required=false) def __init__(self, *args, **kw): """ bit of hackery first name , last name @ top of form instead @ end. """ super(signupformextra, self).__init__(*args, **kw) # put first , last name @ top new_order = self.fields.keyorder[:-2] new_order.insert(0, 'first_name') new_order.insert(1, 'last_name') new_order.insert(2, 'industry') new_order.insert(3, 'occupation') new_order.insert(4, 'bio') new_order.insert(5, 'skills') new_order.insert(6, 'interests') new_order.insert(7, 'phone') self.fields.keyorder = new_order def save(self): """ override save method save first , last name user field. """ # first save parent form , user. new_user = super(signupformextra, self).save() new_user.first_name = self.cleaned_data['first_name'] new_user.last_name = self.cleaned_data['last_name'] new_user.industry = self.cleaned_data['industry'] new_user.occupation = self.cleaned_data['occupation'] new_user.bio = self.cleaned_data['bio'] new_user.skills = self.cleaned_data['skills'] new_user.interests = self.cleaned_data['interests'] new_user.phone = self.cleaned_data['phone'] new_user.save() # userena expects new user form, return new # user. return new_user
and added following projects urls.py
url(r'^admin/', include(admin.site.urls)), (r'^accounts/signup/$', 'userena.views.signup', {'signup_form': signupformextra}) (r'^accounts/', include('userena.urls')),
however must have messed in urls configuration because being displayed helpful error message:
name 'signupformextra' not defined
which says line 14 in urls.py following line:
{'signup_form': signupformextra})
any ideas?
you'll need import signupformextra
urls.py
.
at top of urls.py
:
from accounts.forms import signupformextra
make sure have proper relative path forms.py
. assumes urls.py
in same directory forms.py
.
edit:
just re-read question , saw forms.py
in app named accounts
. adjusted answer you're importing accounts.forms
.
Comments
Post a Comment