Skip to content

Why is constructor of FlaskView called per number of methods? #114

Description

@kidapu

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions