请教关于django获取参数的问题

这是网站结构

图片描述

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

阅读 4.6k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏