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
larkifly
V2EX  ›  Python

webpy 如何获取 form 的错误信息

  •  
  •   larkifly · 2014-10-29 15:25:29 +08:00 · 2679 次点击
    这是一个创建于 3465 天前的主题,其中的信息可能已经有所发展或是发生改变。
    webpy自带的form,当验证出错了,会生成包含有错误信息的html,我现在的需求是,只想获取到单纯的错误信息,不包含任何html标签。举个例子:

    <form name="main" method="post">
    <p class="error"> Try again, AmeriCAN:</p>
    <table>
    <tr>
    <th>
    <label for="boe">boe</label>
    </th>
    <td>
    <input type="text" id="boe" value="12" name="boe"/>
    </td>
    </tr>
    <tr>
    <th>
    <label for="bax">bax</label>
    </th>
    <td>
    <input type="text" id="bax" value="1" name="bax"/>
    <strong class="wrong">Must be more than 5</strong>
    </td>
    </tr>
    <tr>
    <th>
    <label for="moe">moe</label>
    </th>
    <td>
    <textarea id="moe" name="moe">aaaaa</textarea>
    </td>
    </tr>
    <tr>
    <th>
    <label for="curly_">curly</label>
    </th>
    <td>
    <input checked="checked" type="checkbox" id="curly_" value="" name="curly"/>
    </td>
    </tr>
    <tr>
    <th>
    <label for="french">french</label>
    </th>
    <td>
    <select id="french" name="french">
    <option value="mustard">mustard</option>
    <option value="fries">fries</option>
    <option value="wine">wine</option>
    </select>
    </td>
    </tr>
    </table>
    <input type="submit" />
    </form>
    上面是验证出错后返回的form,我现在只想要“Must be more than 5”,应该怎么做?
    3 条回复    2015-04-20 16:37:22 +08:00
    hijoker
        1
    hijoker  
       2015-04-20 11:32:17 +08:00
    我也有这个需求啊,楼主搞定没?
    akin520
        2
    akin520  
       2015-04-20 12:05:03 +08:00
    i = web.input()
    bax = i.get("bax")
    larkifly
        3
    larkifly  
    OP
       2015-04-20 16:37:22 +08:00
    @hijoker 后来是改webpy的源码实现的,webpy源码中已经有地方存储了这些错误信息,只是没提供接口获取,你加个接口就可以了。具体的方法就是在webpy的form.py(119行)文件的class input里加了一个函数def getnote(self):
    return self.note
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   962 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:37 · PVG 05:37 · LAX 14:37 · JFK 17:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.