Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

398
Vistas
How to convert svg string to svg file using Python?

Using AJAX I send a svg image to Django using the following function:

function uploadSVG(){

    var svgImage = document.getElementById("SVG");

    var serializer = new XMLSerializer();
    var svgStr = serializer.serializeToString(svgImage);

    $(document).ready(function(){
        $.post("ajax_upload_svg/",
      {
        csrfmiddlewaretoken: csrftoken,
        svgImage: svgStr
      },
      function(){
        console.log('Done')
      });
    });
}

In Django I end up with the svg image as a string using the following function:

def uploadSVG(request):

    svgImg = request.POST.get('svgImage')

    return HttpResponse('')

The string I get looks like this:

<svg xmlns="http://www.w3.org/2000/svg" id="SVG" width="460" height="300" style="border:2px solid #000000"><rect x="150" y="70" width="160" height="130" fill="#292b2c"/></svg>

How can I convert this svg string into a svg file?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The solution is:

with open("svgTest.svg", "w") as svg_file:
        svg_file.write(svgImg)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda