NoReverseMatch:反转'RPA_tool','(,)'找不到参数。尝试了 1 种模式: ['admin_tool/RPA_tool/(?P<Policy_Number>



我正试图在Django应用程序中创建一个动态URL,以便从搜索页面重定向到RPA_Tool/<保单编号>

当我尝试加载搜索页面时,我收到错误找不到参数为"(",("的"RPA_tool"的反转。尝试了1个模式:[admin_tool/RPA_tool/(?P<Policy_Number>[^/]+(/$']

我试着把它换成了数据显示。Policy_ID,并且已成功重定向到Policy_ID。但是,当我将超链接更改为datadisplay时。Policy_Number,我收到错误。

这是HTML:

<input type="text" id="myInput" onkeyup="searchTable()" placeholder="Search for Policy..">
<table class = "table">
<tr class="header">
<th>Policy ID</th>
<th>Policy Numbers</th>
</tr>

<tbody id="myTable">
{% for datadisplay in Policies %}
<tr>
<td>{{datadisplay.Policy_ID}}</td>
<td>{{datadisplay.Policy_Number}}</td>
<td> <a class="btn btn-sm btn-info" href="{% url 'RPA_tool' datadisplay.Policy_Number %}"> Update </a> </td>
</tr>
{% endfor %}
</tbody>
</table>

Views.py:

def searchPolicies(request):
Policies = getPolicyNumbers()
myfilter = PoliciesFilter()
context = {'myfilter': myfilter}
return render(request, 'admin_tool/search.html', {'Policies':Policies, 'myfilter': myfilter})
def RPA_tool(request): 
if request.method == 'POST':
form = RPA_tool_form(request.POST)
if form.is_valid():
policyNumber = form.cleaned_data.get('Policy_Number')
messages.success(request, f'{policyNumber} Saved')
editRPADetails(form)
return redirect('/admin_tool/')
else:
form = RPA_tool_form(initial={'Policy_Number':'Test'})
return render(request, 'admin_tool/RPA_tool.html', {'form':form})

urls.py:

from django.urls import path
from . import views
# from users import views as user_views

urlpatterns = [
# path('admin/', admin.site.urls),
path('', views.home, name='UW-home'),
path('admin_tool/', views.admin_tool, name ='admin_tool'),
path('RPA_tool/<str:Policy_Number>/', views.RPA_tool, name ='RPA_tool'),
path('about/', views.about, name='Admin_Tool about'),
path('search/', views.searchPolicies, name='searchPolicies')
]

当字段"Policy_Number"为空时会发生这种情况在您的数据库中,您得到了字段Policy_Number为空的模型。你可以在django管理员中查看

相关内容

  • 没有找到相关文章

最新更新