首页 > Web开发 > 详细

基于URL的正则匹配

时间:2018-04-29 18:26:35      阅读:210      评论:0      收藏:0      [点我收藏+]

第一种的方式使用

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

原文:https://www.cnblogs.com/qiangayz/p/8971438.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!