Open
Description
When I run the following code in python 3.6.9, The __init__()
method is called 5 times.
from flask import Flask
from flask_classful import FlaskView, route
app = Flask(__name__)
class AppRouting(FlaskView):
route_base = '/'
def __init__(self):
print("--------constructor---------")
return
def test1(self):
return "test1"
def test2(self):
return "test2"
def test3(self):
return "test3"
def test4(self):
return "test4"
def test5(self):
return "test5"
if __name__ == '__main__':
AppRouting.register(app)
app.run()
Cmdline output is below.
$ python test.py
--------constructor---------
--------constructor---------
--------constructor---------
--------constructor---------
--------constructor---------
* Serving Flask app "F003-server2" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Is this right?
I think the constructor method is called per number of methods.
If possible, I want the constructor to be called only once.
Metadata
Metadata
Assignees
Labels
No labels
Activity