简体   繁体   English

找不到带有参数“()”和关键字参数“ {}”的“ url_name”

[英]Reverse for 'url_name' with arguments '()' and keyword arguments '{}' not found

I'm getting this error after redirecting on a form submit and I don't understand why it happens, I know that posts about this subject aren't missing but after reading dozens of them I'm still not able to fix this issue. 重定向到表单提交后,我收到此错误,但我不明白为什么会发生此事,我知道关于此主题的帖子并未丢失,但是在阅读了数十篇之后,我仍然无法解决此问题。

Reverse for 'commenting_room_detail' with arguments '()' and keyword arguments '{}' not found.  
1 pattern(s) tried: ['room/(?P<gig>\\d+)/(?P<name>[-\\w\\d]+)/$']

Here is what my code looks like : 这是我的代码如下所示:

views.py views.py

if request.method == 'POST':
    form = MessageForm(request.POST)
    if form.is_valid():
        save_it = form.save(commit=False)
        ...
        save_it.save()
        return redirect(reverse('commenting_room_detail'))

urls.py urls.py

url(r'^room/(?P<gig>\d+)/(?P<name>[-\w\d]+)/$', views.commenting_room, name='commenting_room_detail'),

template/ room.html template / room.html

<form method="POST" action="{% url 'commenting_room_detail' room.gig.id request.user %}">...</form>

If someone could explain to me why this error is appearing on this specific code It would help me avoid this common error for the next times, because everything seems correct, thanks. 如果有人可以向我解释为什么此错误出现在此特定代码上,这将有助于我下次避免该常见错误,因为一切似乎都正确,谢谢。


Update here I changed the url destination as shown on the answers below : 在这里更新,我更改了网址目标,如以下答案所示:

return redirect(reverse('commenting_room_detail'), kwargs={'gig': room.gig.id, 'name': request.user})

I still get this error, if the problem is the urls regex patterns how can I resolve this ? 如果问题是网址正则表达式模式,我仍然会收到此错误,我该如何解决呢?

Reverse for 'commenting_room_detail' with arguments '()' and keyword arguments '{}' not found. 
1 pattern(s) tried: ['room/(?P<gig>\\d+)/(?P<name>[-\\w\\d]+)/$']

You need to pass the required keyword arguments for that url to reverse in your view function like you did in your template: 您需要传递必需的关键字参数,以便该url在您的视图函数中像在模板中一样进行reverse

return redirect(reverse('commenting_room_detail', kwargs={...}))
#                                                 ^^^^^^

Here is working example: 这是工作示例:

# views.py
class commenting_room(View):
    pass

# urls.py
url(r'^room/(?P<gig>\d+)/(?P<name>[-\w\d]+)/$', views.commenting_room, name='commenting_room_detail'),

# in code

# NoReverseMatch: Reverse for 'commenting_room_detail' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['room/(?P<gig>\\d+)/(?P<name>[-\\w\\d]+)/$']
reverse('commenting_room_detail')

# success
reverse('commenting_room_detail', kwargs={'gig': 123, 'name': 'test1'})

This is your error: 这是您的错误:

Reverse for 'url_name' with arguments '()' and keyword arguments '{}' not found. 找不到带有参数“()”和关键字参数“ {}”的“ url_name”。 1 pattern(s) tried: ['room/(?P\\d+)/(?P[-\\w\\d]+)/$'] 尝试了1种模式:['房间/(?P \\ d +)/(?P [-\\ w \\ d] +)/ $']

Args issue error: Args问题:

Reverse for 'commenting_room_detail' with arguments '()' and keyword arguments '{}' not found. 找不到带有参数“()”和关键字参数“ {}”的“ commenting_room_detail”。 1 pattern(s) tried: ['room/(?P\\d+)/(?P[-\\w\\d]+)/$'] 尝试了1种模式:['房间/(?P \\ d +)/(?P [-\\ w \\ d] +)/ $']

Double check your url patterns. 仔细检查您的网址格式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用参数&#39;(&#39;&#39;,)&#39;和关键字参数&#39;{}&#39;找不到&#39;###&#39;的反转 - Reverse for '###' with arguments '('',)' and keyword arguments '{}' not found 使用参数'()'和未找到关键字参数'{}'来反转'*' - Reverse for '*' with arguments '()' and keyword arguments '{}' not found 反向找不到&#39;&#39;带参数&#39;&#39;和关键字参数&#39;{}&#39; - Reverse for '' with arguments '' and keyword arguments '{}' not found 反向&#39;&#39;带参数&#39;()&#39;和关键字参数&#39;{}&#39;找不到 - Reverse for '' with arguments '()' and keyword arguments '{}' not found 使用参数'()'和未找到关键字参数'{}'来反转''*'' - Reverse for ''*'' with arguments '()' and keyword arguments '{}' not found Django url end href错误:反向为“”,参数为&#39;(&#39;,)&#39;和关键字参数为&#39;{}&#39; - Django url end href error: Reverse for '' with arguments '('',)' and keyword arguments '{}' not found 反转为&#39;&#39;,未找到参数&#39;()&#39;和关键字参数&#39;{}&#39;。 - Reverse for '' with arguments '()' and keyword arguments '{}' not found. Django:使用参数&#39;(&#39;&#39;,)&#39;和关键字参数&#39;{}&#39;未找到&#39;detail&#39;的反转 - Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found 反向找不到参数&#39;(1,)&#39;和关键字参数&#39;{}&#39;的&#39;data&#39; - Reverse for 'data' with arguments '(1,)' and keyword arguments '{}' not found 找不到参数“(”,)”和关键字参数“ {}”的“详细信息” - Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM