You need to enable JavaScript to run this app. Django路由反向解析命名estimate_u的<int:id>路由报NoReverseMatch错误
优惠活动
大模型
产品
解决方案
定价
更多

Django路由反向解析命名estimate_u的<int:id>路由报NoReverseMatch错误

项目路由配置(urls.py 代码)

我在urls.py文件中编写了如下代码:

urlpatterns=[
     path('estimate_insert/',views.estimate_ui,name='estimate_i'),
     path('<int:id>/',views.estimate_ui,name='estimate_u'),
     path('estimate_delete/<int:id>/',views.estimate_d,name='estimate_d'),
     path('estimate_preview/<int:id>/',views.estimate_preview,name='estimate_v'),
]
对应视图实现(views.py 代码)

上述路由对应我在views.py文件中编写的如下视图函数:

def estimate_ui(request,id=0):
    if request.method=="GET":
        if id==0:
            form=EstimateForm()
        else:
            obj_estimate=Estimate.objects.get(pk=id)
            form=EstimateForm(instance=obj_estimate)
        return render(request,"Invoices/estimate_ui.html",{'form':form})
    
    else: 
        if id==0:
          form=EstimateForm(request.POST)
        else: 
          obj_estimate=Estimate.objects.get(pk=id)
          form=EstimateForm(request.POST,instance=obj_estimate)
        if form.is_valid():
          form.save()
        return redirect('/invoices/')
报错触发与信息说明

我访问如下定义的路由时触发了问题:

path('<int:id>/',views.estimate_ui,name='estimate_u'),

访问过程中收到的报错信息如下:

NoReverseMatch at /invoices/status/3/
Reverse for 'estimate_u' with arguments '('',)' not found. 1 pattern(s) tried: ['estimate/(?P<id>[0-9]+)/$']
Request Method:
GET
Request URL:
http://127.0.0.1:8000/invoices/status/3/
Django Version:
3.1.4
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'estimate_u' with arguments '('',)' not found. 1 pattern(s) tried: ['estimate/(?P<id>[0-9]+)/$']
相关访问链路与问题排查情况
  • 我的应用访问链路为:index.html页面跳转至status.html页面(该页面的链接用于跳转至estimate.html页面),后续跳转至estimate.html页面
  • 这是一个基于工作流的多步骤应用
  • 已查阅平台上几乎所有和URL相关的教程,也检索过公开技术资料,仍未找到可解决问题的方案,希望能得到问题产生原因的解释

内容的提问来源于stack exchange,提问作者Husrat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.07 13:06:03