简体   繁体   中英

Serve react build as a template in flask

I want to serve a react project with Flask. I need the index HTML to be served as a flask template so I can pass in a variable from Flask, and the other static files (css, js, favicons) as normal static files.

How can I achieve that?

Edit: I just had the html sent as a flask template and put the static files into a folder which I declared as the static dir in flask.

As far as I know, you can not do that. Flask uses template htmls that are rendered on the server. Now if you ask whether can you code a react renderer for server-side rendering with Python/flask?, might be possible, I guess. But people built big companies around this idea, for example Vercel. So better team up. What you can do though you can make flask and react communicate through different ports. ie code your Flask back-end as a rest-api and build the react front-end.

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