Django命名组不匹配

时间:2013-12-07 13:14:43

标签: python django django-urls

这些是我的文件:

urls.py:

from django.conf.urls import patterns, include, url
from eiris_wipro.views import *   

urlpatterns = patterns('',
                   (r'^hello/$',hello),
                   (r'^articles/(?P<collection>)/$', restusers),
)

views.py:     来自django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello new world!")

def restusers(request, collection='smthn'):
    print 'Collection', collection
    return HttpResponse(collection)

当我尝试点击http://127.0.0.1:8000/articles/smthn/时,我收到404错误!!

我应该遗漏一些非常基本的东西。可能是什么?

1 个答案:

答案 0 :(得分:5)

你还没有给出任何可以捕获的模式。它应该是:

r'^articles/(?P<collection>\w+)/$'

假设您想要捕获任意数量的字母数字字符。