Linked Questions
64 questions linked to/from How can I use the variables from "views.py" in JavasScript, "<script></script>" in a Django template?
60 votes
8 answers
94k views
Passing Python Data to JavaScript via Django [duplicate]
I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of ...
41 votes
4 answers
48k views
How can I pass my context variables to a javascript file in Django? [duplicate]
This question must be obvious but I can't figure it out. In a template, I link to a js file in my media directory. From that file, I would like to access a context variable like {{my_chart}}. But is ...
10 votes
5 answers
20k views
django best way to pass data to javascript [duplicate]
I used to "tie" my data to the DOM until I've discovered the data binding libraries. My question, say I have a table which contains model records, how can I build that table with JS, i.e pass the ...
2 votes
3 answers
7k views
How to pass Django data to an external JS file? [duplicate]
I am working on a Django project. I would like to pass a data from Django's views.py into a javascript file, run the js function then render the return value into my html page. I am not using a form ...
1 vote
2 answers
2k views
Accessing context variable (a list) in Django Views in Javascript HTML [duplicate]
I am facing some problems trying to access a context variable in my django views in my html javascript. I would like to access 'unclean' context which is a list and USE IT AS A LIST in my html script ...
1 vote
0 answers
1k views
Pass data from django view to Javascript file [duplicate]
I have table data in PostGreSQL which is easily accessed in my Django View. Now I want to pass this data to a javascript .js file whose purpose is to use this data and visualize using d3.js This is ...
1 vote
4 answers
839 views
Use django variables passed as context in script tag (JS) of HTML file [duplicate]
I am stuck using <script> tags to render a googlemaps api window in my django webapp. In my views I passed my data as such: def map_view(request): context = { 'title': 'My Map', ...
0 votes
1 answer
537 views
Update JavaScript with Django view values [duplicate]
In the js file below 'use strict'; $(document).ready(function() { buildchart() $(window).on('resize', function() { buildchart(); }); $('#mobile-collapse').on('click', function()...
0 votes
1 answer
435 views
How to use getElementById in django [duplicate]
I'm trying to generate a code for editing posts using modal that are made before but it shows "Identifier or string literal or numeric literal expected" and "Statement expected" ...
0 votes
0 answers
161 views
Displaying message through window alert in Django templates [duplicate]
I have a django template in which a logged in user can check his/her account balance. The balance is obtained in the django template through a form labelled as 'form0'. Now I want to display this user ...
0 votes
1 answer
53 views
use dict from python in django html template and also in js [duplicate]
I am having a dict statistics in my view.py and give it as param in my context to my index.html. There I want to use it in my html like {{ statistics.key1 }}. But I also want to use it in js. When ...
1 vote
0 answers
47 views
Prepopulating fields of user edit form (also: passing {{user}} into a javascript function?) [duplicate]
Basically, I'm trying to make an edit profile modal with fields that are already prepopulated by the user's original data. I passed django models into my javascript files by using these brackets {{}} ...
31 votes
2 answers
5k views
Are all JSON objects also valid JavaScript objects?
The JSON standard defines objects in one way and the ECMAScript (JavaScript) standard defines it in another. It is often said that JSON objects are a subset of JavaScript objects, is this true? Is ...
8 votes
6 answers
21k views
django: how to pass template variable to javascript onclick routine?
The concept comes from this http://www.prepbootstrap.com/bootstrap-template/real-estate-list-map-dynamic I enable 2 blocks in a django template, left blockshows device info (device name and location ...
5 votes
1 answer
16k views
django variables to javascript
I'm trying to make a gallery page using django/js/jquery. Is it possible to pass django template variables to the javascript? I need to implement for loop like: {% for post in object_list %} {% ...