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

321
Views
React to "click event" in Python (Django)

everyone, beforehand - I'm a bloody but motivated developer beginner.

I am currently trying to react to simple events (click on a button) in the HTML code in my Django project. Unfortunately without success ...

HTML:

<form>
    {% csrf_token %}
    <button id="CSVDownload" type="button">CSV Download!</button>
</form>

JavaScript:

    <script>
        document.addEventListener("DOMContentLoaded", () => {
            const CSVDownload = document.querySelector("#CSVDownload")
            CSVDownload.addEventListener("click", () => {
                console.dir("Test")
            })
        })
    </script>

Do I need JavaScript for this? Or is there a way to react directly to such events in python (Django)?

I am really grateful for all the support.

Since I'm not really "good" yet - a simple solution would be great :)

Python (Django)

    if request.method == "POST":
        projectName = request.POST["projectName"]
        rootDomain = request.POST["rootDomain"]
        startURL = request.POST["startURL"]
....

With this, for example, I managed to react to a kind of event, i.e. when the user sends the form. The problem here, however, is - if I have several forms on one page, then I cannot distinguish which function should be carried out: / I am at a loss

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

0

This World help you HTML

<form>
    {% csrf_token %}
    <button id="CSVDownload" type="button" onclick="download_csv()">CSV Download!</button>
</form>

Javascript

<script>
       function download_csv{
        document.addEventListener("DOMContentLoaded", () => {
        const CSVDownload = document.querySelector("#CSVDownload")
        CSVDownload.addEventListener("click", () => {
            console.dir("Test")
        })
    })

 }
    
</script>

It might be error while writing the function but this is the way how you react by javascript to the click using on click method

about 4 years ago · Juan Pablo Isaza Report

0

Do I need JavaScript for this? Or is there a way to react directly to such events in python (Django)?

I would say that for now JavaScript is the best avenue for you to explore, as whilst there are various ways of getting python to run on the client side (i.e. in your browser), I wouldn't necessarily recommend them to a beginner. Or rather, interpolating them into a Django project might be challenging.

Skulpt

Brython

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!