2011-07-12 17 views
0

我试图在Django中实现搜索机制,但我无法弄清楚什么是最好的方式来做到这一点。Django根据搜索选项的不同视图的搜索机制

我有一个组合框和一个文本框作为海参参数。在“A”和“B”这样的组合框中有两个选项,根据该选项应该运行不同的视图。

但是,因为这两个选项有共同的属性,比如min-max length of textbox等等,我考虑当点击搜索按钮时,应该去一些常见的search view以及在文本框被验证之后,依赖于根据请求,组合框本页中的选项应该重定向到适当的页面。

主/ views.py

def search(request): 
if request.method == 'POST': 
    type = request.POST['searchType'] 
    searchvalue = request.POST['searchvalue'] 
    if len(searchvalue) > 200: 
     return render_response(request, 'search/error.html', {'message':'bidi'}) 

    if type == 'A': 
     return redirect('/A/search/') 
    elif type == 'B': 
     return redirect('/B/search/') 
    else: 
     return render_response(request, 'search/error.html', {'message':'errormessa'}) 

A/views.py

def search(request): 
... 

B/views.py

def search(request): 
... 

然而,如你看,whi我重定向到view Aview B我需要通过searchvalue作为后参数,但我做不到。

此外,我不知道我的结构是否适当和安全地进行此类搜索?实施此类搜索的最佳方法是什么?

谢谢

回答

0

如果您知道javascript,请从javascript中进行搜索(表单提交?);所以基本上你会检查用户选择了什么,并适当选择了端点。