我正在嘗試使用輸入按鈕組制作一個表單,根據他們按下的按鈕將用戶重定向到另一個 URL。當我認為我不應該收到時,我目前正在收到 NoReverseMatch。我瀏覽了什么是 NoReverseMatch 錯誤的最佳答案,我該如何解決?但不要認為這些適用于我。index.html 中的表單: <form action="/main/community/" method="get"> <div class="btn-group" role="group" aria-label="Basic example"> <input type="button" class="btn btn-secondary" value='Comm1'> <input type="button" class="btn btn-secondary" value='Comm2'> <input type="button" class="btn btn-secondary" value='Comm3'> </div> </form>我的網址:app_name = 'main'urlpatterns = [ path('', views.Index, name='index'), path('community/', views.Community, name='community'), path('community/choice',views.CommView, name='CommView'), path('admin/', admin.site.urls)]我的看法:def Community(request): try: pass except (KeyError): pass else: return HttpResponseRedirect(reverse('community/choice'))def CommView(request): return HttpResponse("Test success!.")當我按下按鈕時,不會發生重定向。當我手動輸入的 URL 時,/community/choice/我收到以下錯誤:NoReverseMatch在/main/community/Reverse for 'community/choice' not found. 'community/choice' is not a valid view function or pattern name.
1 回答

浮云間
TA貢獻1829條經驗 獲得超4個贊
我想你應該試試main:CommView。App_name:view_name 就像你在 urls.py 中定義的那樣
在我的項目中,我這樣使用
return reverse('blog:article_detail', kwargs={
'article_id': self.id,
'title': self.title
})
- 1 回答
- 0 關注
- 146 瀏覽
添加回答
舉報
0/150
提交
取消