推荐学习书目
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 · Jan 8, 2018 · 3591 views
    This topic created in 3057 days ago, the information mentioned may be changed or developed.

    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 replies    2018-01-09 10:43:33 +08:00
    okletswin
        1
    okletswin  
       Jan 8, 2018
    看起来请求没到 django,是 js 层的检查结果
    aixia0124
        2
    aixia0124  
       Jan 8, 2018
    还没判断到你自定义的错误就被拦截了,记不清了,好像自定义字段验证错误之前,还有一层 django 的表单验证
    qq976739120
        3
    qq976739120  
       Jan 8, 2018
    加表单验证
    awanabe
        4
    awanabe  
       Jan 8, 2018
    这个是浏览器在 input 上如果有 required 信息的错误提示
    yhqly
        5
    yhqly  
       Jan 9, 2018
    可以提示呀。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2858 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 100ms · UTC 04:53 · PVG 12:53 · LAX 21:53 · JFK 00:53
    ♥ Do have faith in what you're doing.