开发者

Problem with django's url template tag (and reverse() function)

I have the following view function in activities.开发者_StackOverflow社区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?


You didn't define activity_thumbnail in your urls.py

urls.py:

from views import activity_thumbnail
urlpatterns = patterns('',
    url('^activity_thumbnail/$', activity_thumbnail, name='activity_thumbnail')
)

That might seem a bit redundant, but it gives you more freedom in mapping your views into urls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜