5👍
Check the class name in the source code browser.
You can try to change the class name like that:
class MyForm(forms.Form):
error_css_class = "error"
11👍
Just add this CSS
to change error message color:
.errorlist
{
color: red;
}
or if you want to change field border color then
.error input, .error select {
border: 2px red solid;
}
- [Django]-Django Import Issue
- [Django]-Running a Django 1.4-based app on Google App Engine
- [Django]-Named JSON array in Django REST Framework
6👍
I know this is an old question but I needed it as a beginner.
You can extend the ErrorList class in the
django.forms.utils
to style it as you wish.
In my case I wanted it as divs and Bootstrap alerts.
So I did this in forms.py
class DivErrorList(ErrorList):
def __str__(self):
return self.as_divs()
def as_divs(self):
if not self:
return ''
return '<div class="errorlist">%s</div>' % ''.join(['<div class="error alert alert-danger mt-1">%s</div>' % e for e in self])
and in the views.py
form = AddToCartForm(error_class=DivErrorList)
see the documentaion: customizing-the-error-list-format
- [Django]-Successful Django Deploy Through AWS Elastic Beanstalk, But Getting 500 ERROR
- [Django]-Django Private Project Git Repo – Open Source App Repo
- [Django]-Django on Google AppEngine with CloudSQL: How to connect database (Error 2002, Can't connect to local MySQL server..)
5👍
To change the style of the error_message:
1st: Inspect the element of the error_message then copy its class
2nd: Add the style you want …
In my case…. the class of the error_message is help-block
<style>
.help-block{color:red;
font-weight:bold;
}
</style>
JUST DON’T FORGET TO PUT IT INSIDE YOUR {% block content %} or {% block body %} on your html if you extended the base.html or else… it wont work
3rd: That’s All 🙂
- [Django]-Framework/Language for new web 2.0 sites (2008 and 2009)
- [Django]-Humanize in django/python, how to translate