I'm new to Django and HTML.
i have a code like below:
...
<script>
var cars = ["Saab", "Volvo", "BMW"];
</script>
...
I need to pass the var (["Saab", "Volvo", "BMW"])
to my Django view.
I'm new to Django and HTML.
i have a code like below:
...
<script>
var cars = ["Saab", "Volvo", "BMW"];
</script>
...
I need to pass the var (["Saab", "Volvo", "BMW"])
to my Django view.
You can do this with AJAX, send the data via POST and then in the Django view you can access it with request.POST
.
You can use this as a reference:
https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html How do I POST with jQuery/Ajax in Django?