Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbed javascript code in a django template
    text
    copied!<p>Based on this Highcharts example (javascript code included in a HTML): <a href="http://jsfiddle.net/f4Ef7/" rel="nofollow">http://jsfiddle.net/f4Ef7/</a></p> <p>I have a template where I want to embed that JavaScript code without having to include any static. Anything not related with JS is being processed by the browser. Currently my <strong>views.py</strong> looks like:</p> <pre><code># -*- encoding: utf-8 -*- from django.shortcuts import render from django.http import HttpResponse from tfgplot.models import estado_foneras from django.template import RequestContext, loader def index(request): template = loader.get_template('tfgplot/index.html') context = RequestContext(request) return render(request, 'tfgplot/index.html', context) </code></pre> <p>My application is called tfgplot and the template <strong>index.html</strong> looks like:</p> <pre><code>&lt;div id="container" style="min-width: 300px; height: 300px; margin: 1em"&gt; &lt;script src="http://code.highcharts.com/highcharts.js"&gt;&lt;/script&gt; &lt;script src="http://code.highcharts.com/modules/exporting.js"&gt;&lt;/script&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;script type="text/javascript"&gt; {% autoescape off %} $('#container').highcharts({ xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }] }); {% endautoescape %} &lt;/script&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>This should create a graphic like the one that can be seen in the <a href="http://jsfiddle.net/f4Ef7/" rel="nofollow">link</a> but I'm not able to see that graphic I'm expecting, any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload