|
[code brush:python;toolbar:false;]1.定义包装函数
from django.shortcuts import render_to_response
from django.template.context import RequestContext
def template_name(func):
def view(request,template_name,*args,**keys):
result=func(request,*args,**keys)
if type(result)!=dict:
return result
return render_to_response(
template_name,
result,
context_instance=RequestContext(request, result)
)
return view
2.使用
@template_name
def video(request,id):
return {
'video':Video.objects.get(id=id)
}
3.urls.py传入参数
(r'^channel/(?Pid[0-9]+)/page/(?Ppage[0-9]+)',channel_list,
{'template_name': 'videos/channel.html'},"videos_channel"),[/code] |
|