Jinja2 url generation

百般思念 提交于 2019-12-13 01:37:14

问题


<a href="{{ url('affiliate', affiliate=object.slug) }}">{{ object.name }} </a> 

Cause an error: reverse() got an unexpected keyword argument 'affiliate'


回答1:


As your url() function seem to be an alias to the Django's reverse(), the function signature is different from the regular template tag. So just use the reverse() syntax:

<a href="{{ url('affiliate', args=[object.slug]) }}">{{ object.name }}</a>


来源:https://stackoverflow.com/questions/34712469/jinja2-url-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!