0

This is all within Django.

  1. I have a script (let's say script.py) that has a function (let's say function.py), which executes a comparison of two sets, returning a list that contains values that are in one set but not the other.

  2. I have a views.py page that calls the function.py within a view, stores the resulting list in a variable (let's call it result),

  3. I have an HTML template page that the views.py renders. Within this HTML page, I have a table. At the bottom of this page, I have a Javascript section, which contains an Ajax call that takes a user's input of two numbers and upon the clicking of a submit button, returns the "result" via the table.

I can't for the life of me figure out how to render the table with the data from the script. When I run the script, it says in the Javascript console that "result" is not defined. How can I define it?

Here's the code (the Ajax call within the HTML page is at the top and the view that calls the function.py is at the bottom; setlist is the id given to the table within the HTML page that I'd like to render the "result" data in):

1 Answers1

0

From what you're describing, it sounds like the problem isn't with the fact you're using an external script... If it's being imported & properly called from views.py, there shouldn't be a problem.

I'm assuming the problem is with your AJAX calls.

I suggest you read How do I integrate Ajax with Django applications?, which contains a great explanation on using AJAX with Django.

Community
  • 1
  • 1
thomas
  • 1,133
  • 1
  • 12
  • 31