gpt4 book ai didi

python - NoReverseMatch 使用反向和带参数的 url

转载 作者:太空宇宙 更新时间:2023-11-03 18:19:00 25 4
gpt4 key购买 nike

我试图在 django 中使用 reverse 函数,但没有成功。我已经尝试更改参数并使用 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: []

url.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 %}

最佳答案

reverse() 调用不正确,应该是:

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

关于python - NoReverseMatch 使用反向和带参数的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24494244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com