Passing an id in Django url

前端 未结 2 380
猫巷女王i
猫巷女王i 2021-01-11 14:06

I want to pass userid from django url to my view

Here is what I have written in Django template



        
相关标签:
2条回答
  • 2021-01-11 14:25

    No quote ''

    <a href ={% url user_details x.id  %} class='btn btn-primary' style="float: right;" >
        Know More
    </a>
    

    Another your url

    url(r'^User/(?P<userid>\d+)/$', 'search.views.user_detail', name='user_details'), 
    
    0 讨论(0)
  • 2021-01-11 14:28

    Be carefull, after Django 1.5, use must use quotes. I came across this solution and tried it, got an error. I'm using Django 1.6 and you need the quotes:

    <a href ={% url 'user_details' x.id  %} class='btn btn-primary' style="float: right;" >
        Know More
    </a>
    

    hope it helps.

    0 讨论(0)
提交回复
热议问题