样式Django表单错误消息 [英] Style Django form error message

查看:36
本文介绍了样式Django表单错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将django形式的defa错误设为红色和粗体.例如,将此字段必填"设为红色和粗体.我看到error_css_class ='error',但是它不起作用. https://docs.djangoproject.com/en/1.5//ref/forms/api/#django.forms.Form.error_css_class 谢谢!这是我的模型.py

I'm trying to make django form defa error red and bold. For example, make "This field is required" red and bold. I saw error_css_class = 'error' but it's not working. https://docs.djangoproject.com/en/1.5//ref/forms/api/#django.forms.Form.error_css_class Thank you! This is my models.py

class RegiForm(forms.Form):
    error_css_class = 'error'
    DateInput = partial(forms.DateInput, {'class': 'datepicker'})
    email = forms.EmailField(max_length=75)
    first_name = forms.CharField(max_length=25)
    last_name = forms.CharField(max_length=25)
    address = forms.CharField(max_length=200)

这是我的模板:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>RegistrationForm</title>
    </head>
    <body>
        <h1>Registration Form</h1>
        <form action="/login/regi/" method="POST">
            {% csrf_token %}
            {{ form.as_p }}
            <input type="submit" value="Submit" />
        </form>
    </body>
</html>

推荐答案

在源代码浏览器中检查类名称.您可以尝试像这样更改类名:

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"

这篇关于样式Django表单错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆