Adding a Javascript Library

56 views
Skip to first unread message

Haad Khan

unread,
Mar 21, 2014, 2:01:14 AM3/21/14
to web...@googlegroups.com
I am new to web2py and I was wondering how to add a javascript library. Do we add it to view. And how to import it into html. Using the same code <script src=> and what do we even place src=.
I wanted to basically visualize a graph and was planning to use Arbor.js. Also if you know of some better javascript plotting library do mention it. Thanks

Massimo Di Pierro

unread,
Mar 21, 2014, 3:02:56 AM3/21/14
to web...@googlegroups.com
You simply place the file under the application/yourapp/static/js/ folder and you import it from the html.

You can import in the layout.html with <script src="{{=URL('static','js/myfile.js')}}"></script> or you can import it from the python code (model or controller) with

response.files.append(URL('static','js/myfile.js'))

This will generate the <script>...</script> for you. 
Reply all
Reply to author
Forward
0 new messages