Hope to use flask as an intermediary to let Python and JS interaction, we have what better practical experience?

Source: Internet
Author: User
I've tried getjson and stuff like that. But it's better to be suspicious of the size of the data. I remember seeing someone who was pandas+d3.js+flask, but couldn't find it.

Reply content:

Not invited to answer, just because in the flow of information in my homepage to see you more .... This topic selected all kinds of to hit my key ah.

I'm a hard-working porter.


Getting Your python data Onto Browser Describes how to get your Python stats into the browser. So in fact, JSON is the Python and JS intermediary, flask Framework just help you to build a simple JSON server, even restfull are not, if you are only used to visualize. Of course you can also implement the restful services that are modified and deleted. In the same vein, you can use tornado, maybe it has better performance.


I'm assuming a dynamic service, then Panda's dataframe can help you process data quickly, Playing with REALTIME data, Python and D3 , and data visualization using D3.js and Flask are all about the details.


After the feature is implemented, you may be concerned about performance issues. I don't think most of these concerns will be needed. The most annoying possibility is development and maintainability. Of course, if you are concerned about performance, you can also consider the optimization of the server, the introduction of the cache service, server balance and so on when you are fully functional, I think this is not your concern.


In addition, the data visualization control is strongly recommended, you can try Ipython notebook. This visualizing a networkx graph in the IPython notebook with d3.js may make you strongly like IPython notebook.

Beginner's personal experience:
For example, now we're going to transfer one data from JavaScript to flask, and then back to JavaScript after processing. We can use the Getjson in jquery and transfer the data into a string.

Javascript + jQuery:
MyData = {"MSG", "Hello Flask."};          //data to be transferred$.Getjson('/dataconvector ', {              the URL of the function that gets the data in//Flask        MyKey: JSON.stringify(MyData)      //define a keyword to stringify the data    }, function(Data) {                    //data returned from Flask        Console.Log(Data.result);        $( "#result" ).text(Data.result);    });
WebSocket.

Also recommended artifact Github-brython-dev/brython:brython (Browser python) is a implementation of Python 3 running in the Browser

Bottle-websocketflask-socketio, quite simple to use
https:// flask-socketio.readthedocs.org /en/latest/ It is recommended to read this book if you get started:
Data visualization with Python and Javascript-o ' Reilly Media Recommend an open source project above GitHub, Caravel (Github-airbnb/caravel:caravel is a data exploration platform designed to be visual, intuitive , and Interactive ), I am studying and studying it in flask this bag has jsonify this method, can return the return value of this method, in JS side to accept as JSON.

In addition, you can use the Jinja filter to convert the dictionary into a format that JS can read in HTML. The string does not have to be.
Refer to my Blog
http://www. cnblogs.com/lewis617/p/ 5184621.html Use flask to build a restful service that uses JSON as the data interface so that the foreground can get back data. Tornado + WebSocket is also a choice, format JSON is more convenient.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.