TypeError: __init__() got an unexpected keyword argument 'method'

Question:

Well, I am writing a Flask project, but when I tried to python manage.py

The traceback told me that:

Traceback (most recent call last):
  File "manage.py", line 5, in <module>
    from app import db,create_app
  File "/home/humbert/2017-sharing-backend/sharing/app/__init__.py", line 42, in <module>
    app.register_blueprint(main_blueprint, url_prefix='/main')
  File "/home/humbert/venv/local/lib/python2.7/site-packages/flask/app.py", line 64, in wrapper_func
    return f(self, *args, **kwargs)
  File "/home/humbert/venv/local/lib/python2.7/site-packages/flask/app.py", line 951, in register_blueprint
    blueprint.register(self, options, first_registration)
  File "/home/humbert/venv/local/lib/python2.7/site-packages/flask/blueprints.py", line 154, in register
    deferred(state)
  File "/home/humbert/venv/local/lib/python2.7/site-packages/flask/blueprints.py", line 173, in <lambda>
    s.add_url_rule(rule, endpoint, view_func, **options))
  File "/home/humbert/venv/local/lib/python2.7/site-packages/flask/blueprints.py", line 76, in add_url_rule
    view_func, defaults=defaults, **options)
  File "/home/humbert/venv/local/lib/python2.7/site-packages/flask/app.py", line 64, in wrapper_func
    return f(self, *args, **kwargs)
  File "/home/humbert/venv/local/lib/python2.7/site-packages/flask/app.py", line 1043, in add_url_rule
    rule = self.url_rule_class(rule, methods=methods, **options)
TypeError: __init__() got an unexpected keyword argument 'method'

I think my manage.py is right,and I can’t figure out the mistake.

The mistake part of __init__.py is that:

from .main import main as main_blueprint
app.register_blueprint(main_blueprint, url_prefix='/main')

from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix="/auth")

from . import views

I really need some help, thanks!

Asked By: h10g

||

Answers:

I had a similar problem. In my code I had a line

@bp.route('/<init:id>/delete', method=('POST'))

The keyword method needs to be changed to methods(with an s)

Answered By: Nicholas Harder

I had encountered a similar problem in my code and just had to change the keyword “method” to “methods“:

@app.route('/login', methods = ['GET', 'POST'])
Answered By: kalya

Where did you add the above line?
Above the app creation function?

Answered By: Neora Asulin
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.