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

  1. Remove the methods= argument from the shortcut decorator — @app.get already means methods=['GET'].
  2. If the view must handle multiple methods, use @app.route('/x', methods=['GET','POST']) instead of a shortcut.
  3. 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

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


AI-assisted analysis of pallets/flask@6a2f545bfd (2026-07-31). Data as JSON: /data/errors/cb0032d0e6e1e61d.json. Report an issue: GitHub ↗.