如何使用url django发送数据
我想发送{{order.id}},但是在Bellow中获得错误的错误,请帮助我解决问题
views.py:pemby.html:urls.py
def Detail_pem(request, idor):
print(idor)
return render(request, 'store/detail.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' %}"
})
}
path('Detail_pem/<idor>', Detail_pem, name='Detail_pem'),
I want to send {{order.id}}, but getting error like pictuce in bellow, please helping me to solve problem
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'),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在重定向
window.location.href =“ {%url'lote_pem'%}”
没有变量。但是在您的urls.py中,您正在传递
didor
变量。它应该是:
window.location.href =“ {%url'lidet_pem'order.id}%}”
。和您的urls.py对此更改:
int:id
You are redirecting through
window.location.href = "{% url 'Detail_pem' %}"
without a variable.But in your urls.py you are passing
idor
variable.It should be:
window.location.href = "{% url 'Detail_pem' order.id } %}"
.And your urls.py change to this:
int:id