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

362
Visualizações
Django - show result (error) with javascript

I have form, that accepts number between 1-6 and a file. You can see code in my other question: https://stackoverflow.com/questions/43611769/django-javascript-modal-form-validation

I have to validate form, without having to reload it as it is modal form and it closes on refresh (or is should open it on refresh, but i don't really like the idea of reloading). So i want the modal to show error, if there is any (wrong file type, model already exists...) How would i achieve this?

Somebody suggested me to post form asynchronously and show error with javascript. How would i send javascript message from views in django, without the page having to reload? Could it be done with Json? How?

Thank you in advance!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You have to options:

  1. Django validation view which will return JsonResponse
    In that case you send your data to this view which will check if data are valid and return appropriate response. Then you parse response and show error if any.
  2. Javascript validation. You make validator in your javascript code which will check if filetype is suitable etc. Here you have example how to allow only specified types of files.

In both cases you should validate your data in view in which you are saving to Database/server while someone could send data directly to your saving view(e.g. with Postman). I would suggest second approach because it is faster and one less call to server.

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