一个python django的后台函数的问题
#搜索
def search(request):
card_name = None
if 'q' in request.POST:
import re
card_name = re.split('\t','%s'% request.POST.get('q'))
card_name = card_name[0]
request.session['card_name']=card_name
return HttpResponseOpensocialRedirect(reverse('mobile_card_search_by_name', args=[1]))
def search_by_name(request,page=1):
if 'card_name' in request.session:
card_name = request.session.get('card_name',None)
page = int(page)
card_list = Card.get_cache_all()
new_list = []
for card in card_list:
if card_name in card.name:
new_list.append(card)
pager,new_list = get_pager(new_list,10,page)
ctxt = RequestContext(request,{
'pager': pager,
'new_list': new_list,
})
return render_to_response('card/list3.html', ctxt)
def search(request):
card_name = None
if 'q' in request.POST:#post传参,变量名为q
import re
card_name = re.split('\t','%s'% request.POST.get('q'))#以\t为分界符,将q的值划分
card_name = card_name[0]#取得第0个值
request.session['card_name']=card_name#储存在session变量中
return HttpResponseOpensocialRedirect(reverse('mobile_card_search_by_name', args=[1]))#重定向
def search_by_name(request,page=1):
#获得card_name的值
if 'card_name' in request.session:
card_name = request.session.get('card_name',None)
page = int(page)
#获得Card缓存的所有变量
card_list = Card.get_cache_all()
new_list = []
for card in card_list:
#如果card_name在Card缓存变量中,就添加到new_list
if card_name in card.name:
new_list.append(card)
pager,new_list = get_pager(new_list,10,page)#get_pager这个函数应该另外有自定义吧
ctxt = RequestContext(request,{
'pager': pager,
'new_list': new_list,
})
return render_to_response('card/list3.html', ctxt)#重定向