zoukankan      html  css  js  c++  java
  • 基于URL的正则匹配

    第一种的方式使用(

    <li><a  target="_blank"  href="/CC/detail/?nid={{ k}}">{{ row.name }}</a></li>

    url(r'^detail/', views.detail),
    
    http://127.0.0.1:8000/CC/detail/?nid=3
    
    def detail(request):
        print '2222222222222',request.GET
        nid =request.GET.get("nid")
        detail_info = USER_DICT[nid]
        return render(request,'detail.html',{"dict":detail_info})
    
    <ul>
        {% for k,row in user_dict.items %}
            <li><a  target="_blank"  href="/CC/detail/?nid={{ k}}">{{ row.name }}</a></li>
        {% endfor %}
    </ul>

      

    第二种方式:(

    <li><a  target="_blank"  href="/CC/detail-{{ k}}.html">{{ row.name }}</a></li>

    url(r'^detail-(d+).html', views.detail2),
    http://127.0.0.1:8000/CC/detail-1.html
    
    def detail2(request,nid):
        print '2222222222222',request.GET
        # nid =request.GET.get(nid)
        detail_info = USER_DICT[nid]
        return render(request,'detail.html',{"dict":detail_info})
    
    <ul>
        {% for k,row in user_dict.items %}
            <li><a  target="_blank"  href="/CC/detail-{{ k}}.html">{{ row.name }}</a></li>
        {% endfor %}
    </ul>
    

      

    第三种方式,多个值的匹配:

    url(r'^detail-(?P<nid>d+)-(?P<uid>d+).html', views.detail3),
    def detail3(request,**kwargs):
        print kwargs
      
    
    a. 
    url(r'^detail-(d+)-(d+).html', views.detail),
    
    def func(request, nid, uid):
    
    pass
    
    def func(request, *args):
    args = (2,9)
    
    
    def func(request, *args, **kwargs):
    args = (2,9)
    
    b. 
    url(r'^detail-(?P<nid>d+)-(?P<uid>d+).html', views.detail)
    
    def func(request, nid, uid):
    pass
    
    def funct(request, **kwargs):
    kwargs = {'nid': 1, 'uid': 3}
    
    def func(request, *args, **kwargs):
    args = ()
    kwargs = {'nid': 1, 'uid': 3}
    
    
  • 相关阅读:
    GYM 101572C(模拟)
    GYM 101572A(单调队列优化dp)
    Codeforces 183C(有向图上的环长度)
    Codeforces 183A(坐标系性质)
    2019湘潭校赛 G(并查集)
    2019湘潭校赛 H(dp)
    2019湘潭校赛 E(答案区间维护)
    Codeforces 1141F2(贪心、预处理)
    Codeforces Round #411(Div. 2)——ABCDEF
    基数排序学习
  • 原文地址:https://www.cnblogs.com/qiangayz/p/8971438.html
Copyright © 2011-2022 走看看