I am trying to include an HTML when a button is clicked in a Django project but the error a Uncaught SyntaxError: Invalid or unexpected token
Here is the Javascript:
document.getElementById("workout_table").innerHTML = '{% include 'app/log_form.html' %}';
The error showing is at this line of code as if the include code is not there at all.

My question: How can I add this code through javascript and avoid this error
CodePudding user response:
Try something like
document.getElementById("workout_table").innerHTML = {% json.dumps( include 'app/log_form.html') %};
Note the absence of quote marks around {% ... %}, which is based on the assumption that Python's json.dumps method returns a string of characters starting and ending with ASCII double quote marks in the same way as JSON.stringify does in JavaScript.
If the syntax of {% json.dumps( include 'app/log_form.html) %} is incorrect, please amend it to cause the string content of file app.log_form.html to be serialized as a JSON string and included in generated HTML.
CodePudding user response:
Try changing quotation marks to Grave accent :
document.getElementById("workout_table").innerHTML = `{% include 'app/log_form.html' %}`;
