Problems with bringing a photo-like data from an api

1

I have an api that returns data in which I fill in the detatables, in these precise moments I have problems with pulling a data that brings me a picture of a model.

Then I leave the api:

for anuncio in anuncios:
            data = {}
            data['id'] = anuncio['id'],
            data['manifestado'] = anuncio['numero_de_manifiesto'],
            data['nave'] = anuncio['nave__nombre'],
            data['tipo_nave'] = anuncio['tipo_nave__descripcion'],
            data['nombre_linea'] = anuncio['linea_naviera__nombre'],
            data['nro_viaje'] = anuncio['nro_viaje'],
            data['agente_maritimo'] = anuncio['agente_maritimo__nombre'],
            data['eslora'] = anuncio['nave__eslora'],
            data['eta'] = anuncio['eta'],
            data['etb'] = anuncio['etb'],
            data['etc'] = anuncio['etc'],
            data['etd'] = anuncio['etd'],
            data['carga'] = anuncio['carga'].upper()
            data['proyecto_articulo'] = anuncio['proyecto_articulo__nombre']
            # data['amarradero'] = anuncio['amarradero__nombre']
            data['reporte_servicio_url'] = reverse('reporte_servicio', kwargs={"pk": anuncio['id']})
            data['atraque_url'] = reverse('acta_maniobra_imprimir', kwargs={"pk": atra[anuncio['id']]}) if anuncio['id'] in atra else None
            data['desatraque_url'] = reverse('acta_maniobra_imprimir', kwargs={"pk": desa[anuncio['id']]}) if anuncio['id'] in desa else None
            data['foto'] = anuncio['tipo_nave__foto'],

            resultado.append(data)

I also leave the html where I call the data:

columns: [
                {
                    data: "foto",
                },
                {data: "manifestado"},
                {data: "nave"},
                {data: "tipo_nave"},
                {data: "nombre_linea"},
                {data: "nro_viaje"},
                {data: "agente_maritimo"},
                {data: "eslora"},
                {data: "eta"},
                {data: "etb"},
                {data: "etc"},
                {data: "etd"},
                {data: "carga"},
                {data: "proyecto_articulo"},
                {
                    "targets": -1,
                    "data": null,
                    "defaultContent": "<i class=\"fa fa-eye\" aria-hidden=\"true\"></i>",
                    "className": 'anuncio'
                },
                {
                    "targets": -1,
                    "data": null,
                    "defaultContent": "<i class=\"fa fa-eye\" aria-hidden=\"true\"></i>",
                    "className": 'atraque'
                },
                {
                    "targets": -1,
                    "data": null,
                    "defaultContent": "<i class=\"fa fa-eye\" aria-hidden=\"true\"></i>",
                    "className": 'desatraque'
                }
            ],

The problem is that it brings me the url and I was trying with the render and defaultContent, but I do not know how to do it.

Your contribution would be very helpful, I leave a photo of the result. Thanks in advance.

    
asked by Jeanpierre Rivas 17.01.2018 в 23:14
source

1 answer

1

You could add one more column and apply a render to be able to insert the image in the following way:

columnDefs: [{
  targets: 0,
  render: function ( data, type, row, meta ) {
    return '<img src="'+data+'">';
  }
}]

where targets specifies the position of the column where you want the html code to be rendered, and data is the value you receive, in your case the url of your image.

    
answered by 18.01.2018 / 05:15
source