NoReverseMatch公司

2024-05-19 07:43:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个错误,我没有找到解决办法,我得到了ID\u pedido\u ex和cod\u experto关键字,但我仍然抛出错误,请学生帮助?你知道吗

Reverse for 'entregado_ex' with arguments '()' and keyword arguments '{'id_pedido_ex': 11, 'cod_experto': 'VA-0012 '}' not found. 1 pattern(s) tried: ['solicitar/entregar-extra/(?P<id_pedido_ex>\\d+)/(?P<cod_experto>\\d+)/$']

模板呈现期间出错。你知道吗

按钮模板html:

<a href="{% url "usuario:entregado_ex" id_pedido_ex=ex.id cod_experto=ex.articulo_ex.cod_experto %}" method='GET' type="submit" class="btn btn-success pull-right"/>Entregar</a>

全局url:

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

url应用程序:

urlpatterns = [
url(r'^entregar-extra/(?P<id_pedido_ex>\d+)/(?P<cod_experto>[\w-]+)/$',       Update_stockex, name="entregado_ex"),
]

你知道吗视图.py地址:

@login_required
def Update_stockex(request, id_pedido_ex, cod_experto):
if request.method == 'GET':
   pedido = Pedido_Extra.objects.get(id=id_pedido_ex)
   articulo = Articulo.objects.get(pk=cod_experto)
   articulo.stock -= pedido.cantidad_ex
   articulo.save()
   pedido.estado_ex = 'entregado'
   pedido.fecha_entrega_ex = datetime.now()
   pedido.save()
   return HttpResponseRedirect('/solicitar/pedidos-extra/')

你知道吗型号.py地址:

class Articulo(models.Model):
    cod_experto = models.CharField(max_length=999, primary_key=True, blank=True)
    nombre  = models.CharField(max_length=999, blank=True)
    stock  = models.IntegerField(blank=True, default=0)

    def __str__(self):
        return '{}'.format(self.nombre, self.stock) 


class Pedido_Extra(models.Model):
    articulo_ex       = models.ForeignKey('Articulo')
    especialidad_ex   = models.ForeignKey('Especialidad')
    cantidad_ex       = models.IntegerField(blank=True, default=0)

    def __str__(self):
        return '{}'.format(self.articulo_ex, self.especialidad_ex, self.estado_ex, self.cantidad_ex) 

有什么问题?当做!你知道吗


Tags: selfidtrueurlmodelsextraclassex
2条回答

添加一个get\u absolute\u url方法来获取视图的反向

 class Articulo(models.Model):
    cod_experto = models.CharField(max_length=999, primary_key=True, blank=True)
    ...



    def get_absolute_url(self): 
        return reverse('entregado_ex', kwargs={'id_pedido_ex': pedido.id, 'cod_experto':self.code_experto})`

正则表达式中出现错误,请更改[\w-]+)/

收件人:

url(r'^entregar/(?P<id_pedido_ex>\d+)/(?P<cod_experto>[^/]+)/$',   Update_stockex, name="entregado_ex"),

相关问题 更多 >

    热门问题