我的django项目中有这段代码,在我的一个表单中引发了ValidationError
raise forms.ValidationError(mark_safe(_("You don't have enough funds, please click -><a href='%(url)s'> here </a><- go to your account to add funds.")),
code='insufficent_funds',
params={'url':reverse('add_funds')})
不幸的是,当我使用mark safe时,似乎没有处理params(不是正确的单词?)所以html在我的网页上看起来像这样
You don't have enough funds, please click -><a href="http://127.0.0.1:8000/edit/%(url)s"> here </a><- go to your account to add funds.
有什么方法可以解决这个问题吗?
答案 0 :(得分:0)
应该有更好的方法,但解决这个问题的一种方法是
text = "You don't have enough funds, please click -><a href='%s'> here </a><- go to your account to add funds." % reverse('add_funds')
raise forms.ValidationError(mark_safe(_(text)),
code='insufficent_funds',
)