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

270
Views
Injecting js variable in django url

My url looks like this :

path('tree_sensor\/(?P<sensorID>.*)', views.tree_sensor, name='tree_sensor')

and i have a var sID = 1,2,etc which i want to inject into a django url in a button

<a class='popup_button small_text' href='{% url 'agriculture:tree_sensor' "sID" %}'><span>Sensor Page</span></a>")

template:


for (i in motePos) {
    markers.addLayer(mote[i].on('click', function(e) {
        var sID = this.id;
       
        $.ajax({
            type : 'GET',
            url : "{% url 'agriculture:sensor_ms' %}",
            data : {"sID" : sID},
            success: function(response){
               
                var measurement = JSON.parse(response["measurement"]);
                var fields = measurement[0]["fields"];
                console.log(sID)
                mote[i].bindPopup("<h3>Tree Sensor: " + motePosName[i] + "</h3>" 
               "<br><a class='popup_button small_text' href='{% url 'agriculture:tree_sensor' sID %}'><span>Sensor Page</span></a>").openPopup();
                mote[i].name = motePosName[i];
                mote[i].id = motePosId[i];     
            }
        })
    }));

Current url prints "tree_sensor/sID" . I want to get the ID from the objects so it would be something like "tree_sensor/1" "tree_sensor/2" etc.

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

0

As DrummerMann suggested it works out like this :

var sensorID = "href='{% url 'agriculture:tree_sensor' 12345 %}'";
var url_mask = sensorID.replace("12345", fields["sensor"]);

and the button to the link

"<br><a class='popup_button small_text' "+url_mask+" ><span>Sensor Page</span></a>"
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!