Django Book 翻译
菜单>:
TOC
返回
原文:
This concept is best explained by example. If we had instead used the pattern ``'^time/'`` (without a dollar sign at the end), then *any* URL that starts with ``time/`` would match, such as ``/time/foo`` and ``/time/bar`` , not just ``/time/`` . Similarly, if we had left off the initial caret character (``'time/$'`` ), Django would match *any* URL that ends with ``time/`` , such as ``/foo/bar/time/`` . Thus, we use both the caret and dollar sign to ensure that only the URL ``/time/`` matches. Nothing more, nothing less.
翻译:
最好还是用范例来说明一下这个概念。如果我们用 ``'^time/'`` (结尾没有$), 那么以 ``time/`` 开始的 *任意* URL 都会匹配,比如 ``/time/foo`` 和 ``/time/bar`` , 不仅仅是 ``/time/`` 。同样的,如果我们去掉最前面的 ^ ( ``'time/$'`` ), Django 一样会匹配由 ``time/`` 结束的 *任意* URL ``/time/`` ,比如 ``/foo/bar/time/`` 。 因此,我们必须同时用上 ^ 和 $ 来精确匹配 URL ``/time/`` 。不能多也不能少。
备注:
译者: