This article gives a brief introduction of creating RESTful API using python flask library.

python package

Flask useful functions:

  • Flask
  • render_template
  • jsonify
  • request
  • url_for
  • redirect
  • make_response

Refer the flask API document.

Run flask server

Configure the ip and port then launch the flask server.

Route

Return html

html with flask

Below is the html code if you want to get the relative filepath such as the css files and the js files.

index.html

In order to get the relative files, we also need to configure CORS setting.

server.py

Startup the flask server by command line:
python server.py

RESTful API return JSON

GET

POST

最後修改日期: 2022-01-26

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。