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

131
Views
How to call a Python function with vanilla Javascript in a Django app

I am working on a Django app and I am trying to call a Python function in views.py on a button click. I am trying to call this function using vanilla JavaScript if possible, because I am very unfamiliar with JavaScript and would like to try to keep things simple. The idea would be to display the text returned by the hello() function by using JavaScript to create a new div after the button is clicked. I believe I can do that part, but I have not been able to find any information on calling the Python function. I have the JavaScript function alerting with the text for now. Here is a sample of my code so far:

./views.py

def hello():
  return "Hello world"

./static/js/index.js

document.getElementById('button').addEventListener('click', printHello);

function printHello() {
  var text = // call Python function
  alert(text);
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's as simple as this.

views.py

def hello():
    return "Hello World"

urls.py

urlpatterns = [
    path('Hello/', views.hello, name='hello')
]

javascript

fetch('http://localhost:3000/Hello')
  .then(data => console.log(data)); //Hello World
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!