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

164
Visualizações
Save uploaded file Django Jquery Ajax

I am quite new in Python and Django and because im working on a big porject it's a bit difficult to see what I'm doing wrong. I would like to save the uploaded File in my repository folder.

<form action="/action_page.php" enctype="multipart/form-data">
            <label for="myfile">Select a file:</label>
            <input type="file" id="myfile" name="myfile" multiple="multiple" />
            <br /><br />
            <input id="upload_submit" type="submit" />
</form>

This is my views file, I dont really understand how the communication between the modules work here

@csrf_exempt
def get_text(self, request):
    rand_int = random.random()
    return JsonResponse({"text": "Random number: " + str(rand_int)}, status=200)

@csrf_exempt
def save_uploaded_file(self, request):
    rand_int = random.random()
    return JsonResponse({"text": "Random number: " + str(rand_int)}, status=200)

My urls look like this

urlpatterns = [
    path("admin/", admin.site.urls),
    path("save_uploaded_file/", url_Handler_Wrapper.save_uploaded_file, 
name="save_uploaded_file"),
    path("get_text/", url_Handler_Wrapper.get_text, name="get_text"),
    path("tasks/", url_Handler_Wrapper.run_task, name="run_task"),
    path("", url_Handler_Wrapper.home, name="home"),
]

And this is my javascript

$('#upload_submit').on('click', function() {

    var formData = new FormData(Document.querySelector('#myfile'))
    $.ajax({
       url: '/save_uploaded_file/',
       type: 'POST',
       data: formData,
       success: function (response) {
           if (response) {
               formData.write("/")
           }
       },
       error: function (error) {
           console.log(error)
       },
       cache: false,
       contentType: false,
       processData: false
  });
  return false;
});
over 4 years ago · Santiago Trujillo
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