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 6877845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:38:59+00:00 2026-05-27T04:38:59+00:00

I have written myself a form: class Autopoweroff_Form(forms.Form): autopoweroff_groups = forms.CharField(required=True) autopoweroff_groups_hosts = forms.CharField(required=True)

  • 0

I have written myself a form:

class Autopoweroff_Form(forms.Form):
    autopoweroff_groups = forms.CharField(required=True)
    autopoweroff_groups_hosts = forms.CharField(required=True)
    autopoweroff_groups_start = forms.CharField(required=True)
    autopoweroff_groups_end = forms.CharField(required=True)
    autopoweroff_groups_startup_delay = forms.CharField(required=True)
    autopoweroff_groups_idle_time = forms.CharField(required=True)

Now I know that I would not have to explicitly set reuqired=True but bear it for now please.
Anyways, let’s press on.

Now since I hate doing validation and so on in the view I just defined an update function for that form:

    def update(self, data):
        if not self.is_bound and data is not None:
            raise Exception()

        if self.is_valid():
            curr_group = self.cleaned_data['autopoweroff_groups']
            ...

and then in my view call it like so:

if request.method == 'POST':
        form = Autopoweroff_Form(data=request.POST)
        form.update(data=request.POST)
        return HttpResponseRedirect('/admin/thin/create_autopoweroff')
    else:
        form = Autopoweroff_Form()

    ...

Now the problem is that If I don’t type anything in the form the form is returned as is without displaying any errors like it ought to. I also know that it wont do anything because:

https://docs.djangoproject.com/en/1.3/ref/forms/validation/

In fact, Django will currently completely wipe out the cleaned_data dictionary if there are any errors in the form. However, this behavior may change in the future, so it’s not > a bad idea to clean up after yourself in the first place.

if i try:

def update(self, data):
        if not self.is_bound and data is not None:
            raise Exception()

        if self.is_valid():
            curr_group = self.cleaned_data['autopoweroff_groups']
            ...
        else:
            print self.errors

I get the errors that I would have liked to see in the template.
I also already tried:

def clean_autopoweroff_groups(self):
        autopoweoff_groups = self.cleaned_data.get('autopoweroff_groups', "")
        if autopoweoff_groups == '':
            print "Validation Error"
            raise forms.ValidationError('Please Enter A Name')
        return autopoweroff_groups

What exactly am I doing wrong?

UPDATE:
in my view:

    if request.method == 'POST':
        form = Autopoweroff_Form(data=request.POST)

        if form.is_valid():
            form.update(data=request.POST)
            return HttpResponseRedirect('/admin/thin/create_autopoweroff')
    else:
        form = Autopoweroff_Form()

and in my form remove if self.is_valid()

  • 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-27T04:39:00+00:00Added an answer on May 27, 2026 at 4:39 am

    Django has build in validation so you don’t need to rewrite it:

    class Autopoweroff_Form(forms.Form):
        # I suggest not prefixing your fields with the name of the class
        groups = forms.CharField(required=True)
        hosts = forms.CharField(required=True)
        start = forms.CharField(required=True)
        end = forms.CharField(required=True)
        delay = forms.CharField(required=True)
        idle_time = forms.CharField(required=True)
    

    and in your view:

    if request.method == 'POST':
        form = Autopoweroff_Form(data=request.POST)
        if form.is_valid():
            return HttpResponseRedirect('/admin/thin/create_autopoweroff')
    else:
        form = Autopoweroff_Form()
    

    note that you call is_valid() in the view, not the form.

    If you want to perform so more complicated validation on either individidual fields or on a grouping of fields, you can overwrite the forms clean() and clean_[field_name]() methods.

    See here:

    https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute

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

Sidebar

Related Questions

I have a program which i have myself written in java, but I want
How do recursive ascent parsers work? I have written a recursive descent parser myself
I have an object not written by myself that I need to clone in
Although I wouldn't have written it myself, what is the expected result of the
I have written this code for myself(it is not a home work) I want
I have written an artifical neural network (ANN) implementation for myself (it was fun).
I have written myself a web crawler using simplehtmldom, and have got the crawl
For a program that I have written myself, is there a method of accessing
I am using a distributed continuous integration tool which I have written by myself
I have a problem with the Jakarta Commons HttpClient. Before my self-written HttpServer gets

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.