将django传递的变量{{}}放入{%url%}中 [英] Putting django passed variables {{}} inside {% url %}

查看:48
本文介绍了将django传递的变量{{}}放入{%url%}中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这样做

<form action="{% url 'add_participant' id={{event.id}} %}" method="POST">

但是django似乎不喜欢在{%%}中包含一个{{}}变量,我该如何解决?

But it seems that django doesn't like having a {{}} variable inside {%%}, how do I work around this?

推荐答案

您不要在模板标签中用双花括号括住变量.大括号用于在模板中呈现变量,而不是在模板标记中传递参数.因此,您将其写为:

You don't surround the variables in a template tag with double curly brackets. The curly double brackets are used to render variables in the template, not to pass parameters in a template tag. You thus write this as:

<form action="{% url 'add_participant' id=event.id %}" method="POST">

这篇关于将django传递的变量{{}}放入{%url%}中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆