2011-02-12 100 views
2

所以我有這個URL方案:。我究竟做錯了什麼?

(r'^test/(?P<name>\d+)/', 'test'), 

def test(request, name): 
    html = "it worked" 
    return HttpResponse(html) 

然而,當我去下面的網址,我得到一個404錯誤: http://127.0.0.1:8000/test/words/

我在做什麼錯?

回答

4

你可能想用的,而不是\w,例如: -

(r'^test/(?P<name>\w+)/', 'test'), 

\d比賽唯一數字; \w匹配任何字母數字字符。由A.M.提供的

Python Regular Expression HOWTO了Kuchling。

+0

我好無聊!感謝您指出。 – 2011-02-12 03:23:30