apiguy / flask-classy

Class based views for Flask
http://packages.python.org/Flask-Classy/
Other
541 stars 68 forks source link

custom init with non-optional param, gives error. #38

Closed Lynges closed 11 years ago

Lynges commented 11 years ago

Trying to create a subclass of FlaskView with a custom init like so:

class BaseView(FlaskView):
    def __init__(self, model):
        pass

gives this error:

File "flask_classy.py", line 162, in make_proxy_method
    i = cls()
TypeError: __init__() takes at least 2 arguments (1 given)

Error disappears when custom init is removed. I am using this to set a model class on the view instance. This lets me create a basic REST interface that I can extend per model class, but the basic CRUD operations are defined here in the base class.

ivan-kleshnin commented 11 years ago

As FlaskView classes are created automatically, i doubt you can customize __init__ signature. Extension knows nothing about what argument you want to pass into. Define model class as class attribute (can even be further customized via @property feature).

P.S. For now FlaskClassy deals bad with inheritance. I advice you to be not bound with it for some time...

apiguy commented 11 years ago

@ivan-kleshnin is correct.