django的url模板标签(和reverse()函数)的问题
我在 activities.views 中有以下视图函数:
def activity_thumbnail(request, id):
pass
我正在尝试在我的模板之一中获取该视图的 URL。 当我尝试以下操作时:
{% url activities.views.activity_thumbnail latest_activity.id %}
我收到以下错误:
渲染时捕获异常: 反转“” 带参数 '(449L,)' 和关键字 未找到参数“{}”。
当我尝试以下操作时,我得到同样类型的错误:
{% url activities.views.activity_thumbnail request,latest_activity.id %}
当我尝试命名参数时:
{% url activities.views.activity_thumbnail id=r.latest_activity.key.id %}
我得到:
渲染时捕获异常: 反转“” 带参数“()”和关键字 未找到参数“{'id': 449L}”。
我做错了什么?
I have the following view function in activities.views:
def activity_thumbnail(request, id):
pass
I'm trying to get the URL for that view in one of my templates.
When I try the following:
{% url activities.views.activity_thumbnail latest_activity.id %}
I get the following error:
Caught an exception while rendering:
Reverse for ''
with arguments '(449L,)' and keyword
arguments '{}' not found.
I get the same kind of error when I try the following:
{% url activities.views.activity_thumbnail request,latest_activity.id %}
When I try named parameters:
{% url activities.views.activity_thumbnail id=r.latest_activity.key.id %}
I get:
Caught an exception while rendering:
Reverse for ''
with arguments '()' and keyword
arguments '{'id': 449L}' not found.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有在
urls.py
中定义activity_thumbnail
这可能看起来有点多余,但它让您可以更自由地将视图映射到 url。
You didn't define
activity_thumbnail
in yoururls.py
That might seem a bit redundant, but it gives you more freedom in mapping your views into urls.