简体   繁体   中英

Fetch Flask Data from python

I have some code from python that displays a table using Flask and render template. I'd like to place this into my React App.js file how can I do this?

My CRUD from python

I'd like to place that into App.js.

Thanks in Advance.

You can create API in flask and call from react js with axios package. Install axios with

npm install axios

Simple Example: Suppose you API is localhost:8080/hello

and it returns "Hello world"

In app.js imports,

import axios from "axios";

and in return

return (
<div>
axios.get("localhost:8080/hello")
</div>
)

References: https://www.npmjs.com/package/axios

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM