如何使用Url Django发送数据



我想发送{{订单。Id}},但是出现如下图的错误,请帮忙解决

误差

Views.py:

def Detail_pem(request, idor):
print(idor)
return render(request, 'store/detail.html' )

pemby.html:

<!-- <a href="{% url 'Detail_pem' %}"><button data-product="{{order.id}}" data-act="{{order.name}}" class="btn btn-warning id_order btntam" >Detail</button> </a> -->
<button data-product="{{order.id}}" data-act="{{order.name}}" class="btn btn-warning id_order btntam" >Detail</button> 
<a href="{% url 'Detail_pem' idor=order.id %}"></a>
</td> 
</tr>
{% endfor %}
</tbody> 
</table>
</div> 
<!-- <script type="text/JavaScript" src="{% static 'js/pem.js' %}"></script> -->

<script>
var id_order = document.getElementsByClassName('id_order')
for (i = 0; i < id_order.length; i++) {
id_order[i].addEventListener('click', function(){
var orid  = this.dataset.product
var ornm  = this.dataset.act
console.log('orid :', orid)
console.log('ornm :', ornm)
window.location.href = "{% url 'Detail_pem'  %}"
})

}

urls . py:

path('Detail_pem/<idor>', Detail_pem, name='Detail_pem'),

您正在重定向通过不带变量的window.location.href = "{% url 'Detail_pem' %}"

但是在你的urls.py中你传递的是idor变量

应该是:window.location.href = "{% url 'Detail_pem' order.id } %}".

你的url .py改成这样:int: id

#if you are passing integer
path('Detail_pem/<int:id>', Detail_pem, name='Detail_pem'),
#or if you are passing string
path('Detail_pem/<str:id>', Detail_pem, name='Detail_pem'),

相关内容

  • 没有找到相关文章

最新更新