Flask general

Start the application

Start the application which the python file is flask_example.py and run it on the port 5001 with the debug options:
flask --app flask_example run --port 5001 --debug

Routes

List all routes mapping:
Suppose your flask application file is flask_example.

Multiple ways:

1) With the cli flask command
flask --app flask_example routes
Under the hood, it imports your flask application file and so it loads its code.
Then it uses the value of the attribute : flask_example.app.url_map.

    Endpoint    Methods  Rule
    ----------  -------  -----------------------
    add_person  POST     /api/person
    foo         GET      /foo
    static      GET      /static/<path:filename>


2) From a REPL:
Concretely, we need to perform things performed by the previous way.

>>> import flask_example
2023-03-23 15:51:58,690 - INFO : sqlalchemy.engine.Engine._exec_single_context  select pg_catalog.version()
    .....................
>>> flask_example.app.url_map
Map([<Rule '/static/<filename>' (HEAD, GET, OPTIONS) -> static>,
 <Rule '/foo' (HEAD, GET, OPTIONS) -> foo>,
 <Rule '/api/person' (OPTIONS, POST) -> add_person>])
Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *