django url的引用
url
1.直接引用
#url(r'^blog/index/$','blog.views.index'),
2.导入
#from blog.views import index
url(r'^blog/index/$',index),
3.在开始默认传参
urlpatterns = patterns('blog.views',
url(r'^blog/index/$','index'),
)
4.直接加参数 可以访问127.0.0.1:8000/blog/index/12-----两位参数
#url(r'^blog/index/\d{2}/$','index'),
url 参数传递
1.带参数名称的
url(r'^blog/index/(?P<id>\d{2})/$','index'),
P 是参数名称,对应到views.py文件中
def index(req,id):
#zidian
user = {'name':'km_moon','age':30,'sex':'female'}
#person
#user = Person('km_moon',33,'female')
#list
book_list = ['python','java','php','Ruby','node.js']
return render_to_response('index.html',{'title':'my page','user': user,'book_list': book_list,'id':id})
2.不带参数名称的
url(r'^blog/index/(\d{2})/$','index'),
P 是参数名称,对应到views.py文件中
def index(req,parm):
#zidian
user = {'name':'km_moon','age':30,'sex':'female'}
#person
#user = Person('km_moon',33,'female')
#list
book_list = ['python','java','php','Ruby','node.js']
return render_to_response('index.html',{'title':'my page','user': user,'book_list': book_list,'id':parm})