2012-08-08 63 views
0

我在URL.py文件Django的:從URL捕獲的數據將無法正常工作

(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

\d+表示一個或多個數字

DMo32zPB15具有數字和字母。改爲嘗試r'^confirm/([a-zA-Z0-9]+)/$'

有關正則表達式的更多信息,請參見http://www.regular-expressions.info以獲得您的閱讀樂趣。

+0

謝謝,我對「數字」的定義過於寬泛。我雖然因爲某些原因包含了字符。 – 2012-08-08 03:50:16

+0

嗯,奇怪。即使文件現在讀取'(r'^ confirm /(\ [a-zA-Z0-9] +)/ $',確認)'它仍然會給出錯誤。 – 2012-08-08 03:52:39

+0

你爲什麼要在那裏放一個反斜槓? '\ d +'被我建議的位取代。 – Amber 2012-08-08 03:54:57

3

這與您的其他問題有關\d+\d+僅匹配數字。您的網址包含非數字(如字母)的內容。您應該看看我在回答您的其他問題時鏈接到的正則表達式教程,並在嘗試編寫使用它們的URL匹配器之前深入瞭解正則表達式。