Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
invalid literal for int() with base 10: '1,303'

I get get error invalid literal for int() with base 10: '1,303' and it shows the blow code at fault. The old data works fine, its just for new stuff i add to the database. Any ideas?

    def get(self, request, *args, **kwargs):
    cart = self.get_object()
    item_id = request.GET.get("item")
    delete_item = request.GET.get("delete", False)
    flash_message = ""
    item_added = False
    if item_id:
                    item_instance = get_object_or_404(Variation, id=item_id) ...
        qty = request.GET.get("qty", 1)
        try:
            if int(qty) < 1:
                delete_item = True
        except:
            raise Http404
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is why you should use django forms instead of pulling data direct off request.GET or request.POST. Django forms provide you with data validation which helps you avoid this kind of thing. The problem is the extra ',' in your supposed int.

int('1,303')

Will produce the error above. The following will not:

int('1,303'.replace(',',''))

So the obvious remedy then is to pass your int through such a filter.

item_instance = get_object_or_404(Variation, id=int(item_id.replace(',',''))
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda