pallets/flask · error · TypeError
Use the 'route' decorator to use the 'methods' argument.
Error message
Use the 'route' decorator to use the 'methods' argument.
What it means
The method shortcut decorators (@app.get, @app.post, @app.put, @app.delete, @app.patch) each hard-code a single HTTP method via _method_route. Passing methods= to them is contradictory — the shortcut already decides the method — so Flask raises TypeError instead of silently merging or overriding.
Source
Thrown at src/flask/sansio/scaffold.py:291
"""The Jinja loader for this object's templates. By default this
is a class :class:`jinja2.loaders.FileSystemLoader` to
:attr:`template_folder` if it is set.
.. versionadded:: 0.5
"""
if self.template_folder is not None:
return FileSystemLoader(os.path.join(self.root_path, self.template_folder))
else:
return None
def _method_route(
self,
method: str,
rule: str,
options: dict[str, t.Any],
) -> t.Callable[[T_route], T_route]:
if "methods" in options:
raise TypeError("Use the 'route' decorator to use the 'methods' argument.")
return self.route(rule, methods=[method], **options)
@setupmethod
def get(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
"""Shortcut for :meth:`route` with ``methods=["GET"]``.
.. versionadded:: 2.0
"""
return self._method_route("GET", rule, options)
@setupmethod
def post(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
"""Shortcut for :meth:`route` with ``methods=["POST"]``.
.. versionadded:: 2.0
"""
return self._method_route("POST", rule, options)View on GitHub ↗ (pinned to 6a2f545bfd)
Solutions
- Remove the methods= argument from the shortcut decorator — @app.get already means methods=['GET'].
- If the view must handle multiple methods, use @app.route('/x', methods=['GET','POST']) instead of a shortcut.
- Alternatively stack shortcuts (@app.get and @app.post) on the same function with distinct endpoints only if the logic truly differs.
Example fix
# before
@app.get('/items', methods=['GET', 'POST'])
def items(): ...
# after
@app.route('/items', methods=['GET', 'POST'])
def items(): ... Defensive patterns
Strategy: validation
Validate before calling
# WRONG: @app.get('/x', methods=['POST'])
# RIGHT: choose one form:
@app.route('/x', methods=['GET', 'POST'])
def view(): ... Prevention
- Never combine methods= with the shortcut decorators (@app.get/@app.post/etc.) — they hard-code the method
- Use @app.route(...) whenever a view accepts multiple HTTP methods
- Lint for the pattern r'@\w+\.(get|post|put|delete|patch)\(.*methods=' in CI
When it happens
Trigger: @app.get('/x', methods=['GET','POST']) or any bp.post/put/delete/patch call that includes a methods= keyword in its options.
Common situations: Migrating from @app.route(..., methods=[...]) to the 2.0+ shortcut decorators and leaving the methods kwarg behind; copy-pasted route definitions; code generators emitting both forms.
Related errors
- The setup method '{f_name}' can no longer be called on the a
- Allowed methods must be a list of strings, for example: @app
- View function mapping is overwriting an existing endpoint fu
- 'endpoint' may not contain a dot '.' character.
- 'view_func' name may not contain a dot '.' character.
AI-assisted analysis of pallets/flask@6a2f545bfd (2026-07-31).
Data as JSON: /data/errors/cb0032d0e6e1e61d.json.
Report an issue: GitHub ↗.