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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:01:57+00:00 2026-06-02T07:01:57+00:00

I was trying to add some custom error messages to a form like this

  • 0

I was trying to add some custom error messages to a form like this one:

class RegistrationForm(forms.ModelForm):

    class Meta:
        model = User  
        fields = ('email',)

    extra_field = forms.CharField(error_messages={
        'required':'Este campo es requerido'
    })     

I have no problem adding custom error messages to a field that is declared in the form (extra_field), but I’m having trouble adding custom error messages to the fields inherited from the model User via meta class (email).

What I really want is to customize all the error messages of this form. Also, I would like to display them in spanish, not english.

So far I have not found any documentation about how to customize the form fields inherited from the model User, I don’t really want to write a new form just because of the error messages.

Thanks in advance!!!

PD: I’m using Django 1.4 and python 2.6.6 in a debian squeeze box.

  • 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-02T07:01:58+00:00Added an answer on June 2, 2026 at 7:01 am

    Ok guys, thank you all for your answers, in fact you helped me a lot!!!

    I solved the problem like this:

    Suposse I have this form:

    class RegistrationForm(forms.ModelForm):
    
      class Meta:
        model = User  
        fields = ('username', 'email')
    

    And I want to add custom error messages to the username field, but I don’t want to loose all the validation that already comes with that field.

    I added this method to my RegistrationForm class:

    def clean_username(self):
        data = self.cleaned_data
    
        # My extremely important validation.
        if len(data['username']) == 5:
    
          self.fields['username'].error_messages["myerror"] = "The important message"
          raise forms.ValidationError(self.fields['username'].error_messages["myerror"])
    
        return data['username']
    

    The advantage of this aproach is that I don’t loose the other validation checks that already come with the field in question.

    This is important because now I don’t have to validate that the user already exists in my database.

    Thanks for your responses, have a good day!!!

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

Sidebar

Related Questions

I was trying to make a custom application form. I've added some control like
I'm trying to add some custom filter methods to my magento module. I though
I am trying to add some custom QGraphicsItems in a QGraphicsScene on mouse click
i'm trying to add some custom attributes to the checkout(sales) page of magento 1.5.1.0
Im trying to add some short file names to a Wise installer to fix
I'm trying to add some accessibility for screen readers into a Flash application, and
I'm trying to add some security to my ASP.NET 1.0 MVC app (VB), but
So I'm trying to add some ability to my project to allow user-defined properties
I'm trying to add some twitter funcionality to my website (php). I publish links
I am trying to add some additional logic to the 'Promoted to front page'

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.