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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:00:36+00:00 2026-06-08T06:00:36+00:00

working on django forms here and i’ve trouble with errors. I know how to

  • 0

working on django forms here and i’ve trouble with errors. I know how to detect them but i cannot (for some reasons) print an error under a form when is is uncorrect.

The class :

class descclient_form(forms.Form):

TYPE_CHOICE = (
('C', ('Client')),
('F', ('Facture')),
('V', ('Visite'))
)

file_type = forms.ChoiceField(choices = TYPE_CHOICE, widget=forms.RadioSelect)
file_name = forms.CharField(max_length=200)
file_cols = forms.CharField(max_length=200, widget=forms.Textarea)
# file_date = forms.DateField()
file_sep = forms.CharField(max_length=5, initial=';')
file_header = forms.CharField(max_length=200, initial='0')

# Check if file_cols is correctly filled
def clean_cols(self):
    cleaned_file_type = self.cleaned_data.get("file_type")
    cleaned_file_cols = self.cleaned_data.get("file_cols")

    if cleaned_file_type == 'C':
        if 'client' not in cleaned_file_cols:
            self._errors['file_cols'] = [u'Requiers \'Client\' in collumn selection']
            print 'error'
    if cleaned_file_type == 'F':
        mandatory_field = ('fact', 'caht', 'fact_dat')
        for mf in mandatory_field:
            if mf not in cleaned_file_cols:
                self._errors["file_cols"] = self.error_class(['Requiers \'fact\', \'caht\' \'fact_dat\ in file_cols'])
                print 'error'
    return self.cleaned_data

Here is the function called :

def descclient(request):

if request.method == 'POST':
    form = descclient_form(data=request.POST)
    if form.is_valid():
        form.clean_cols()
return render_to_response('descclient.html', {'form': descclient_form}, context_instance=RequestContext(request))

And Template :

<form action="/descclient" method="post">
<div class="fieldWrapper">
    {{ form.file_type_errors }}
    <label for="id_subject">File type:</label>
    {{ form.file_type }}
</div>

<div class="fieldWrapper">
    {{ form.file_name_errors }}
    <label for="id_subject">File name:</label>
    {{ form.file_name }}
</div>

<div class="fieldWrapper">
    {{ form.file_cols_errors }}
    <label for="id_subject">Collumns:</label>
    {{ form.file_cols }}
</div>

<div class="fieldWrapper">
    {{ form.file_sep_errors }}
    <label for="id_subject">Separator:</label>
    {{ form.file_sep }}
</div>

<div class="fieldWrapper">
    {{ form.file_header_errors }}
    <label for="id_subject">Header:</label>
    {{ form.file_header }}
</div>
{% csrf_token %}
<p><input type="submit" value="Validate"></p>

For some reaons the “{{ form.file_cols_errors }}” doesn’t print anything

EDIT :

So, as pointed i changed the clean_cols method to clean. I must be some kind of lost because it doesn’t even get into the if statement

def clean(self):
    cleaned_data = super(descclient_form, self).clean()
    cleaned_file_type = cleaned_data("file_type")
            cleaned_file_cols = cleaned_data("file_cols")

    if cleaned_file_type == 'C':
        if 'client' not in cleaned_file_cols:
            raise forms.ValidationError("This field throws an error")
    if cleaned_file_type == 'F':
        mandatory_field = ('fact', 'caht', 'fact_dat')
        for mf in mandatory_field:
            if mf not in cleaned_file_cols:
                raise forms.ValidationError("This field throws an error")
    return cleaned_data
  • 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-06-08T06:00:38+00:00Added an answer on June 8, 2026 at 6:00 am

    You should raise a ValidationError in a “clean_file_cols” method:

    raise forms.ValidationError("This field throws an error")
    

    For details, have a look at the documentation. And btw: You should avoid using “print” anywhere in your django project, because on most webserver configuration, it leads to a server error. Use logging instead.

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

Sidebar

Related Questions

I'm working in Django, and using urllib2 and simplejson to parse some information from
I am working to use django's ContentType framework to create some generic relations for
Getting started with Django 1.3 here. Loving the system so far, but struggling on
Well, I have one form, similar to dajax django forms example, all is working
I'm working on a Django project. But my problem is on JQuery. I used
I'm using django-registration for registration and login purpose. My Models and Forms.py are working
class Story(db.Model): title = db.StringProperty(required=True) slug = db.StringProperty(required=True) I'm working with Django's forms on
i have uploaded a video to django and it's all working fine .. but
I'm working through the random machine example , but I'm having trouble. I've installed
I've started working on Django forms since not long ago. I've been letting forms

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.