1. 程式人生 > >基於URL的正則匹配

基於URL的正則匹配

def htm view int python views html true detail

第一種的方式使用

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>

  

第二種方式:

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的正則匹配