Django Book 翻译
菜单>:
TOC
返回
原文:
Note that Python will raise a ``ValueError`` exception if you call ``int()`` on a value that cannot be converted to an integer, such as the string ``'foo'`` . However, in this example we dont have to worry about catching that exception, because we can be certain ``offset`` will be a string containing only digits. We know that because the regular-expression pattern in our URLconf ``(\d{1,2})`` captures only digits. This illustrates another nicety of URLconfs: they provide a fair level of input validation.
翻译:
注意Python可能会在你调用 ``int()`` 来转换一个不能转换成整数时抛出 ``ValueError`` 异常,例如字符串 ``'foo'`` 。 当然,在这个范例中我们不用担心这个问题,因为我们已经确定 ``offset`` 是 只包含数字字符的字符串。因为正则表达式 ``(\d{1,2})`` 只提取数字字符。 这也是URL配置的另一个好处:提供了清晰的输入数据有效性确认。
备注:
译者: