我在activities.views中有以下 View 函数:
def activity_thumbnail(request, id):
pass
我正在尝试在我的模板之一中获取该 View 的 URL。 当我尝试以下操作时:
{% url activities.views.activity_thumbnail latest_activity.id %}
我收到以下错误:
Caught an exception while rendering: Reverse for '' with arguments '(449L,)' and keyword arguments '{}' not found.
当我尝试以下操作时,我遇到了同样类型的错误:
{% url activities.views.activity_thumbnail request,latest_activity.id %}
当我尝试命名参数时:
{% url activities.views.activity_thumbnail id=r.latest_activity.key.id %}
我得到:
Caught an exception while rendering: Reverse for '' with arguments '()' and keyword arguments '{'id': 449L}' not found.
我做错了什么?
最佳答案
您没有在urls.py
中定义activity_thumbnail
urls.py:
from views import activity_thumbnail
urlpatterns = patterns('',
url('^activity_thumbnail/$', activity_thumbnail, name='activity_thumbnail')
)
这可能看起来有点多余,但它让您可以更自由地将 View 映射到 URL。
关于django - django的url模板标签(和reverse()函数)的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1989338/