[英]passing ID parameter inside anchor href in Django template language
My model name is keybase model and database is stored in mongo DB and object id can be accessed by '_id'.我的 model 名称是密钥库 model,数据库存储在 mongo DB 中,object id 可以通过“_id”访问。 In views i have made object of that view
在视图中,我制作了该视图的 object
What i want is to make a delete button which goes in function of views along with object ID that is coming from mongodb我想要的是制作一个删除按钮,该按钮进入 function 视图以及来自 mongodb 的 object ID
Here is the code of anchor这是锚的代码
<a href="{% url 'Keybase_Management_System:Delete_Keybase' {{ i |mongoid:'_id'}} %}" role="button" aria-pressed="true" style="font-size:11px; display: inline;">
i the parameter value and mongoid: '_id' is custom tag that converts object _id to string id now this is showing parsing error that i 参数值和 mongoid: '_id' 是自定义标签,可将 object _id 转换为字符串 id 现在显示解析错误
could not parse the remainder: '{{' from '{{'
无法解析剩余部分:来自“{{”的“{{”
What actually works实际有效的方法
If i use this {{ i |mongoid:'_id'}}
separately it shows correct results for instance 9kas83n8d893n but i want to move this id as parameter which i am not able to do.如果我单独使用这个
{{ i |mongoid:'_id'}}
它会显示正确的结果,例如 9kas83n8d893n 但我想将此 id 作为参数移动,但我无法做到这一点。
{{ i |mongoid:'_id'}}
works perfectly unless it is sent as as parameter inside anchor tag in href I know there is some sort of syntax error there might be way to send this but i am not able to figure it out {{ i |mongoid:'_id'}}
工作完美,除非它作为参数在 href 中的锚标记内发送我知道有某种语法错误可能有办法发送但我无法弄清楚
Remove the curly braces and try this below -删除花括号并在下面试试这个 -
<a href="{% url 'Keybase_Management_System:Delete_Keybase' i|mongoid:'_id' %}" role="button" aria-pressed="true" style="font-size:11px; display: inline;">
You should not have curly braces inside {% %}
. {% %}
内不应有花括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.