NoReverseMatch使用reverse和url with args

时间:2014-06-30 15:56:47

标签: python django django-urls

我试图在django中使用reverse函数而没有运气。我已经尝试更改args并使用long,int,string,unicode-string等的所有组合,但错误相同。

请帮忙吗?感谢。

我收到错误:

Exception Type: NoReverseMatch at /ajax/data-request
Exception Value: Reverse for 'views.watch' with arguments '(1, 1, 'aaa')' and keyword arguments '{}' not found. 0 pattern(s) tried: []

urls.py:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', views.index, name='index'),
    url(r'^options/', views.options, name='options'),
    url(r'^recuperar-contrasena/', views.recover_password, name='recover_password'),
    url(r'^ajax/login', views.login_ajax, name='login_ajax'),
    url(r'^ajax/data-request', views.data_request, name='data_request'),
    url(r'^peliculas-populares', views.movies_popular, name='movies_popular'),
    url(r'^peliculas-todas', views.movies_all, name='movies_all'),
    url(r'^watch/(?P<is_movie>\d+)-(?P<id>\d+)/(?P<name>.*)$', views.watch, name='watch')
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

反向功能:

'watch-url': reverse('views.watch', None, [(is_movie), (movie.id), (slugify(movie.title))])

{% url %}适用于我的模板:

{% url "watch" 1 movie.id movie.title|slugify %}

1 个答案:

答案 0 :(得分:1)

reverse()来电不正确,应该是:

reverse('watch', None, [(is_movie), (movie.id), (slugify(movie.title))]