Django上的NoReverseMatch

Django上的NoReverseMatch

我不知道为什么会出什么问题,他们能帮助我吗?预先感谢,问候!

Reverse for 'entregado' with arguments '()' and keyword arguments '{'cod_experto': 'ASE-0048', 'id_pedido': 1770}' not found. 1 pattern(s)      tried: ['solicitar/confirmar/(?P<id_pedido>\\d+)/(?P<cod_experto>\\d+)/$']


模板呈现admindata.html时出错,第74行出错:

<td><a href="{% url "usuario:entregado" id_pedido=ped.id cod_experto=ped.articulo.cod_experto  %}" method='GET' type="submit" class="btn btn-success pull-right" value="editar" onclick="document.location.reload();"/>Entregar</a></td>


全局网址:

urlpatterns = [
# Examples:
url(r'^solicitar/', include(urls, namespace="usuario")),
]


网址APP:

urlpatterns = [

url(r'^confirmar/(?P<id_pedido>\d+)/(?P<cod_experto>\d+)/$', login_required(Update_stock), name='entregado'),
]


和views.py:

def Update_stock(request, id_pedido, cod_experto):
if request.method == 'GET':
   pedido = Pedido.objects.get(id=id_pedido)
   articulo = Articulo.objects.get(id=cod_experto)
   articulo.stock -= pedido.cantidad
   stock.save()
return render(request, 'admindata.html', {'pedido':pedido, 'articulo':articulo})

最佳答案

您的cod_experto值为“ ASE-0048”,它与正则表达式\d+不匹配-仅与整数匹配。

如果您希望能够接受这样的值,则需要更改正则表达式:

r'^confirmar/(?P<id_pedido>\d+)/(?P<cod_experto>[\w-]+)/$',

关于python - Django上的NoReverseMatch,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42859225/

10-11 21:31