You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would see this as a typical scenario, having a route without path arguments for POST requests and another endpoint with path arguments for GET requests in the target route.
However, when I send a POST request to the redirecter, url_for("target", arg=arg) generates '/target?arg=xyz'. When I send a GET request to the redirecter, it will generate the expected '/target/xyz'.
I can fix the redirecter for the POST request by explicitely defining url_for("target", arg=arg, _method="GET").
So I could adjust the redirecter to something like:
I do understand, why this is happening. For the POST method, there is no endpoint including <arg> defined, which is why url_for() cannot resolve it and appends it as query argument thereafter.
However, this is the point where I am going to. For me, it was not intuitive, that url_for() uses the method of the current request context to generate its output. Currently, the documentation states:
_method (str | None) – If given, generate the URL associated with this method for the endpoint.
Might this be worth to pick up in the documentation?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello folks,
I stumbled upon an unexpected behavior recently, which I assume might be worth to pick up in the documentation.
Let's take this simple application:
app.py
index.html
I would see this as a typical scenario, having a route without path arguments for
POST
requests and another endpoint with path arguments forGET
requests in thetarget
route.However, when I send a
POST
request to theredirecter
,url_for("target", arg=arg)
generates'/target?arg=xyz'
. When I send aGET
request to theredirecter
, it will generate the expected'/target/xyz'
.I can fix the
redirecter
for thePOST
request by explicitely definingurl_for("target", arg=arg, _method="GET")
.So I could adjust the
redirecter
to something like:I do understand, why this is happening. For the
POST
method, there is no endpoint including<arg>
defined, which is whyurl_for()
cannot resolve it and appends it as query argument thereafter.However, this is the point where I am going to. For me, it was not intuitive, that
url_for()
uses the method of the current request context to generate its output. Currently, the documentation states:_method (str | None) – If given, generate the URL associated with this method for the endpoint.
Might this be worth to pick up in the documentation?
Beta Was this translation helpful? Give feedback.
All reactions