0

我的 URL.py 文件中有以下语句

(r'^confirm/(\d+)/$', confirm)

但是这个网址

http://127.0.0.1:8000/confirm/DMo32zPB15

返回这个

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/confirm/DMo32zPB15
Using the URLconf defined in BBN.urls, Django tried these URL patterns, in this order:
^login/$
^ajax/login$
^ajax/login/nact/$
^ajax/login/nact/cancel//$
^ajax/login/nact/resend/$
^confirm/(\d+)/$
The current URL, confirm/DMo32zPB15, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file Change that to False, and Django will display a standard 404 page.

为什么它不能识别 URL?

4

2 回答 2

4

\d+表示一位或多位数字

DMo32zPB15既有数字又有字母。试试r'^confirm/([a-zA-Z0-9]+)/$'吧。

有关正则表达式的更多信息,请访问 http://www.regular-expressions.info以供您阅读。

于 2012-08-08T03:48:13.440 回答
3

这与您关于\d+. \d+只匹配数字。您的 URL 包含非数字的内容(如字母)。在尝试使用它们编写 URL 匹配器之前,您应该查看我在回答您的其他问题时链接的正则表达式教程,并牢牢掌握正则表达式。

于 2012-08-08T03:48:15.593 回答