关于网友提出的“请教关于django获取参数的问题”问题疑问,本网通过在网上对“请教关于django获取参数的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:请教关于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/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
解决方案1:这块写反了吧?是\d
而不是/d
url(r'/(?P\d{2})$','index.views.index')
参考:https://docs.djangoproject.com/en/1.7/topics/http/urls/#named-groups
以上介绍了“请教关于django获取参数的问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1369586.html