如何使用url django发送数据

发布于 2025-01-31 12:52:50 字数 1467 浏览 1 评论 0原文

我想发送{{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

Image Error

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-02-07 12:52:50

您正在重定向
window.location.href =“ {%url'lote_pem'%}”没有变量。

但是在您的urls.py中,您正在传递didor变量。

它应该是:window.location.href =“ {%url'lidet_pem'order.id}%}”

和您的urls.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'),

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

#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'),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文