zoukankan      html  css  js  c++  java
  • 保留原页面的参数条件

    保留原页面搜索条件
      实现方式一:
        列表页面:
          获取当前所有条件,添加到
            - 编辑按钮的URL后面
            - 添加按钮的URL后面
        编辑或添加页面:
          - POST提交时,获取原来列表页面传过来的条件
          - 拼接URL /hosts/?原来的条件

        list页面:

          list_condition = request.GET.urlencode()

          {% for item in host_list %}
          <li>{{ item }} <a href="/edit/54/?{{ list_condition }}">编辑</a></li>
          {% endfor %}

        add/edit页面:http://127.0.0.1:8000/edit/10/?page=5&id__gt=4
          def edit_host(request,pk):
            if request.method == "GET":
              return render(request,'edit_host.html')
            else:
              # 修改成功 /hosts/?page=5&id__gt=4
              url = "/hosts/?%s" %(request.GET.urlencode())
              return redirect(url)

      实现方式二:
        list页面: http://127.0.0.1:8000/hosts/?page=5&id__gt=4

          params = QueryDict(mutable=True)  #如果是对象调用该方法(需要加下划线):params._mutable = True
          params['_list_filter'] = request.GET.urlencode()
          list_condition = params.urlencode()


          {% for item in host_list %}
          <li>{{ item }} <a href="/edit/54/?{{ list_condition }}">编辑</a></li>
          {% endfor %}

        add/edit页面:http://127.0.0.1:8000/edit/54/?_list_filter=page%3D5%26id__gt%3D4

          def edit_host(request,pk):
            if request.method == "GET":
              return render(request,'edit_host.html')
            else:
              # 修改成功 /hosts/?page=5&id__gt=4
              url = "/hosts/?%s" %(request.GET.get('_list_filter'))
              return redirect(url)

  • 相关阅读:
    HDU 6125
    HDU 6129
    Super Jumping! Jumping! Jumping!
    HDU 1040 As Easy As A+B(排序)
    VS2015转VS2008
    HDU 1329 Hanoi Tower Troubles Again!(乱搞)
    HDU 1062 Text Reverse(字符串)
    HDU 1013 Digital Roots(字符串)
    HDU 1003 Max Sum(动态规划)
    HDU 1203 I NEED A OFFER!(01背包)
  • 原文地址:https://www.cnblogs.com/wangbaihan/p/8060331.html
Copyright © 2011-2022 走看看