如何根据您在django中单击的链接更改数据库筛选器?

时间:2013-07-01 20:29:30

标签: python django

我想点击我的Django页面上的链接,根据我点击的链接显示列表中该名称的新数据库查询过滤器

            <tr>
                <th>RootGroup List</th>

            </tr>

                {% for status in root %}
            <tr>
            <td><a href={{status.rootgroup }}> {{ status.rootgroup }} </a></td>
        #I WANT TO CLICK THE LINK AND DISPLAY A NEW DATABASE BASED ON THE NAME WITH A FILTER OF THE NAME
            </tr>

                {% endfor %}

def display(request):
    x = re.search('d.*','% url ''detail'' poll.id %')

    rootFilter = Viewroot.objects.filter(rootstatus__gt=0, type = 1, ("LINK NAME")).values('rootgroup').distinct() #RootGroup List
    #return render_to_response('status/index.html', { 'root' : rootFilter  },context_instance=RequestContext(request))
    #return HttpResponse( x.group(0)),render_to_response('status/index.html', {'app' : appFilter})
    return HttpResponse("You displayed ", j )`

1 个答案:

答案 0 :(得分:0)

基本上,您可以在named groups模式中使用urls.py来完成这项工作,例如:

(r'^links/(?P<value>\w+)/$', display)

然后,您可以在视图中访问已保存的网址部分,例如:

def display(request, value=None):
    print value

当然,您应该在模板中使用适当的网址:

<td><a href="links/{{ status.rootgroup }}/"> {{ status.rootgroup }} </a></td>

另见documentation