这是网站结构
mywebsute下的urls.py内容:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'/(?P<id>/d{2})$','index.views.index')
)
然后index下views.py的内容:
from django.shortcuts import render_to_response
# Create your views here.
def index(req, id):
return render_to_response('index.html', {'id':id})
那么现在问题是,我在浏览器输入“127.0.0.1:8000/12”,浏览器提示404 not found:
Using the URLconf defined in mywebsite.urls, Django tried these URL patterns, in this order:
1.^admin/
2./(?P/d{2})$
The current URL, 12, didn't match any of these.
我只是希望在首页上获取一个数字给id,为什么会这样呢?
补充一下:Django 1.7,Python 3.4
这块写反了吧?是
\d
而不是/d
参考:https://docs.djangoproject.com/en/1.7/topics/http/urls/#named-groups