Skip to main content
edited tags
Link
MD. Khairul Basar
  • 5.1k
  • 15
  • 43
  • 65
Source Link

django: list transfer to template and to JS

In Views.py i create a list variable -

mortgages_counter.append(MonthlyPaymentAmount) 

it is transferred to .html template as:

<input id ='mortgages_counter' name='mortgages_counter' type='hidden' value='{{mortgages_counter}}'> 

in JQuery (separate file i have to check if each element of this list is used). value is transferred to .js file as:

var mortgages_counter = $('#mortgages_counter').val(); 

but according to console it was transferred as a string to Jquery - like ['1234','125'] and its length is 1 because of some reason, also check like access to index [0] gives - ' and [1] - 1 etc. how to operate with this list as with LIST and NOT a string?