Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6037255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:02:47+00:00 2026-05-23T06:02:47+00:00

I have a trouble with pre-population of the forms in Django. Because debuggin tool

  • 0

I have a trouble with pre-population of the forms in Django. Because debuggin tool in Aptana doesn’t work well, I couldn’t detect the error.
I think when I try form = MemberSettings(default_data) form tries to validate the data and it gives errors for invalid fields even in first load.

Could you help me to find out the problem ?

Thanks

forms.py

class MemberSettings(forms.Form):
email = forms.EmailField(label=_("member_Email"),required = True)
currentPassword = forms.CharField(label=_("member_currentPassword"),widget=forms.PasswordInput,required=False)
newPassword = forms.CharField(label=_("member_newPassword"),widget=forms.PasswordInput,required=False)
newPasswordRe = forms.CharField(label=_("member_newPasswordRe"),widget=forms.PasswordInput,required=False)
emailPreference = forms.ChoiceField(label=_("member_email_preference"), widget=forms.RadioSelect(renderer=HorizRadioRenderer),choices = UserMailPreference.USER_MAIL_PREF,required = True)
gender = forms.ChoiceField(label=_("member_gender"), widget=forms.RadioSelect(renderer=HorizRadioRenderer),choices = UserGender.USER_GENDER ,required = False)
birthYear = forms.ChoiceField(label=_("member_birthyear"),required = False)
education = forms.ChoiceField(label=_("member_education"),choices = UserEducation.USER_EDU, required = False)

def __init__(self,*args, **kwargs):
    super(MemberSettings,self).__init__(*args, **kwargs)
    now = datetime.datetime.now()

    birthYearList = []
    for i in reversed(range (now.year-80,now.year-13)):
        birthYearList.append((i,str(i)))
    self.fields["birthYear"].choices = birthYearList

def clean_currentPassword(self):
    field_data = self.cleaned_data['currentPassword']

    if len(field_data) <= 0:
        return field_data

    if len(field_data.split(' ')) != 1:
        raise forms.ValidationError(_('member_err_password_empty_char'))

    if len(field_data) > 32:
        raise forms.ValidationError(_('member_err_password_maxChar'))

    if len(field_data) < 5:
        raise forms.ValidationError(_('member_err_password_minChar'))

    return field_data

def clean_newPassword(self):
    field_data = self.cleaned_data['newPassword']

    if len(field_data) <= 0:
        return field_data

    if len(field_data.split(' ')) != 1:
        raise forms.ValidationError(_('member_err_password_empty_char'))

    if len(field_data) > 32:
        raise forms.ValidationError(_('member_err_password_maxChar'))

    if len(field_data) < 5:
        raise forms.ValidationError(_('member_err_password_minChar'))

    return field_data

views.py

@login_required
def settings_edit(request):
u = request.user
if request.method == 'POST':
    form = MemberSettings(request.POST)
    if form.is_valid():

        return redirect('/member/settings_edit/')
    else:
        return render_response(request, 'member/settings_edit.html', {'form': form})
else:
    default_data = {
            'email': u.email,
            'gender': u.get_profile().gender,
            'education': u.get_profile().education,
            'birthYear': u.get_profile().birthyear,
            'emailPreference': u.get_profile().mail_preference,
            }
    form = MemberSettings(default_data)
    return render_response(request, 'user/settings_edit.html', {'form': form})
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:02:48+00:00Added an answer on May 23, 2026 at 6:02 am

    You need to use the initial argument when constructing your form instance in the view:

    form = MemberSettings(initial=default_data)
    

    See https://docs.djangoproject.com/en/1.3/ref/forms/api/ for more information. Hope that helps you out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m having some trouble in understanding how delegates in C# work. I have many
Actually I have trouble naming the title of this post. Because I don't know
I have trouble comparing 2 double in Excel VBA suppose that I have the
I have trouble with the following piece of code. When I go through with
I have trouble using Perl grep() with a string that may contain chars that
I have trouble defining a trigger for a MySQL database. I want to change
I have trouble when designing classes like this class C1 { public: void foo();
I have trouble accessing filestream via SqlFileStream. Sql server and IIS7 are on different
I have trouble where, for some reason, SVN would only merge the newly generated
I have trouble launching Glassfish v3 on Mac In Windows, after installation of Glassfish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.