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

264
Visualizações
Pass data from JS to Python via Django

I want to send data from python to JS in Django. I successfully see the data in the response in the browser, but JS returns as empty string. What would be the reason?

trying to fetch information;

def XXX(request):
    message_id=request.POST.get('messageid')
    return render(request, 'XX.html')

sender;

    y = json.loads(response.text)
    ts = str(y["file"]["shares"]["public"]["XX"][0]["ts"])
    return render (request, 'problemduyurusucreate.html', {'ts':ts})

JS;

    <script type=text/javascript>
    function slacksil() {
  html2canvas(document.getElementById("main"), {
    letterRendering: 1,
    allowTaint: true,
    useCORS: true,})
  .then(function (canvas) {
  swal({
    title: "Emin misiniz?",
    text: "Duyuru Kanaldan Silinecek!",
    icon: "warning",
    buttons: true,
    dangerMode: true,})
  .then((willDelete) => {
  if (willDelete) {
    document.getElementById("result").src = canvas.toDataURL("image/png", 0.5);
    var deneme = "{{ ts }}";
    $.ajax({
    type: "POST",
    url: "{% url 'slacksilproblem' %}",
    data: { 
    "messageid": deneme,
    csrfmiddlewaretoken: '{{ csrf_token }}'}})
  swal({
    title: "Duyuru Kanaldan Silindi!",
      icon: "success",})} 
  else {
  swal("İşlem İptal Edildi!", {
    icon: "error",});}});
        })
        .catch((e) => {
            alert(e);
        }); 
}
  </script>

but I am displaying in my browser that I have successfully pulled the data enter image description here

first im sending post request to python for sending image after python script python send to html message timestamp id; enter image description here

then post requst to delete message with timestamp id, but its comes empty to python. But when I look at the answer in the browser, I see that the data is coming enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I solved the problem by sending the data to the cookie with python and retrieving the data from again python.

sender data to cookie ( x is my data );

    html = HttpResponse("<h1>TP</h1>")
    html.set_cookie('ts', x, max_age = None)
    return html

and fetch data in another fonc. like this;

message_id=request.COOKIES['ts']

finally delete cookie;

html.delete_cookie('ts','!') 
about 4 years ago · Juan Pablo Isaza 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