V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
tunnyios
V2EX  ›  Python

Django 自定义错误提示不生效

  •  
  •   tunnyios ·
    chenzao1024 · 2018-01-08 10:56:51 +08:00 · 2558 次点击
    这是一个创建于 2293 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Django,遇到一个问题,在自定义错误信息 required 的时候,不生效。

    class CommentForm(forms.Form):
        name = forms.CharField(max_length=50, error_messages={'required': '用户名不能为空'})
        comment = forms.CharField(
            widget=forms.Textarea(),
            error_messages={'required': '评论不能为空'},
            validators=[words_validator]
            )
    

    required 不生效,界面不填写直接提交,不能够显示自定义的提示

    Alt text

    5 条回复    2018-01-09 10:43:33 +08:00
    okletswin
        1
    okletswin  
       2018-01-08 11:02:44 +08:00
    看起来请求没到 django,是 js 层的检查结果
    aixia0124
        2
    aixia0124  
       2018-01-08 11:30:35 +08:00
    还没判断到你自定义的错误就被拦截了,记不清了,好像自定义字段验证错误之前,还有一层 django 的表单验证
    qq976739120
        3
    qq976739120  
       2018-01-08 11:36:50 +08:00
    加表单验证
    awanabe
        4
    awanabe  
       2018-01-08 13:18:09 +08:00
    这个是浏览器在 input 上如果有 required 信息的错误提示
    yhqly
        5
    yhqly  
       2018-01-09 10:43:33 +08:00
    可以提示呀。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1148 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:46 · PVG 07:46 · LAX 16:46 · JFK 19:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.