gpt4 book ai didi

javascript - Django - 使用 Javascript 将 ID 传递到 url 模板标记中

转载 作者:行者123 更新时间:2023-12-03 01:12:29 26 4
gpt4 key购买 nike

如何使用 JavaScript 在 url 模板标记中插入 id?我尝试了这种方法,但没有得到它。在 urls.py 中找不到路由。

function Edit(pk){
window.location.assign("{% url 'authentication:edit_user' "+${pk}+" %}");
}
<!-- Other way -->
function Edit(pk){
window.location.assign("{% url 'authentication:edit_user' "+pk+" %}");
}

错误是:

Reverse for 'edit_user' with arguments '('+${pk}+',)' not found. 1 pattern(s) tried: ['authentication\/user\/edit\/(?P[0-9]+)\/$']

最佳答案

这不可能行得通。模板标签在客户端 Javascript 运行之前就在服务器端进行评估。

关于javascript - Django - 使用 Javascript 将 ID 传递到 url 模板标记中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52158303/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com