django列表筛选功能的实现

views,中设置请求的类型

class LawDetailView(View):
    def get(self, request, law_id):
        type = request.GET.get('type', '')
        law =  Law.objects.get(id=law_id)

        return render(request, 'zcfg-detail.html', {
            'law': law,
            'type': type,
        })

templates,,中设置:

<div class="col-lg-12" style="margin-bottom: 20px;">
                <a class="{% if type == '' %}btn btn-danger{% else %}btn btn-default{% endif %}" href="?type=" role="button">全部a>
                <a class="{% if type == 'fl' %}btn btn-danger{% else %}btn btn-default{% endif %}" href="?type=fl" role="button">法律a>
                <a class="{% if type == 'xzfg' %}btn btn-danger{% else %}btn btn-default{% endif %}" href="?type=xzfg" role="button">行政法规a>
                <a class="{% if type == 'bmgz' %}btn btn-danger{% else %}btn btn-default{% endif %}" href="?type=bmgz" role="button">部门规章a>
                <a class="{% if type == 'dfgz' %}btn btn-danger{% else %}btn btn-default{% endif %}" href="?type=dfgz" role="button">地方规章a>
            div>

你可能感兴趣的:(django)