Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
how to get a variable value from form to python function in django from javascript

I am trying to scan QR code using javascript as shown below. this part is working fine:

<title>Django Online Barcode Reader</title>
<meta charset="utf-8">
 
{% csrf_token %}

<script src={% static "html5-qrcode.min.js"%}></script>
<style>
.result{
background-color: green;
color:#fff;
padding:20px;
}
.row{
display:flex;
}
</style>

<!--<form action="" method="POST">-->
{% csrf_token %}
<div class="row">
<div class="col">
<div style="width:500px;" id="reader"></div>
</div>
<div class="col" style="padding:30px;">
<h4>SCAN RESULT</h4>
<!--<div id="result" name="result">Result Here</div>-->
<output type="post" id="result" name="resutl" placeholder="qrCodeMessage">
  
</div>
</div>

<script type="text/javascript">
function onScanSuccess(qrCodeMessage) {
document.getElementById('result').innerHTML = '<span class="result">'+qrCodeMessage+'</span>';}

function onScanError(errorMessage) {
//handle scan error
}

var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess, onScanError);
</script>

But I need to pass the value of result variable to python function as following and print it but did not work. It does not print any!

def userspage(request):
    if request.method == 'POST':
        result = request.POST.get("result")
        context = {}
        print(result)
        return render(request, 'users.html', context)

I need your usual help to fix this. Thanks,

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have a typo in line

<output type="post" id="result" name="resutl" placeholder="qrCodeMessage">

change it to name="result"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!