mirror of https://github.com/pallets/flask.git
Allow self as an argument to url_for
This makes the Flask.url_for self argument positional only (Flask supports Python 3.8+) thereby restoring the ability to pass self as a value argument to url_for.
This commit is contained in:
parent
b7c1290528
commit
438edcdf01
|
@ -8,6 +8,7 @@ Unreleased
|
|||
``importlib.metadata.version("flask")``, instead. :issue:`5230`
|
||||
- Restructure the code such that the Flask (app) and Blueprint
|
||||
classes have Sans-IO bases. :pr:`5127`
|
||||
- Allow self as an argument to url_for. :pr:`5264`
|
||||
|
||||
|
||||
Version 2.3.3
|
||||
|
|
|
@ -952,6 +952,7 @@ class Flask(App):
|
|||
|
||||
def url_for(
|
||||
self,
|
||||
/,
|
||||
endpoint: str,
|
||||
*,
|
||||
_anchor: str | None = None,
|
||||
|
|
|
@ -161,6 +161,13 @@ class TestUrlFor:
|
|||
assert flask.url_for("myview", id=42, _method="GET") == "/myview/42"
|
||||
assert flask.url_for("myview", _method="POST") == "/myview/create"
|
||||
|
||||
def test_url_for_with_self(self, app, req_ctx):
|
||||
@app.route("/<self>")
|
||||
def index(self):
|
||||
return "42"
|
||||
|
||||
assert flask.url_for("index", self="2") == "/2"
|
||||
|
||||
|
||||
def test_redirect_no_app():
|
||||
response = flask.redirect("https://localhost", 307)
|
||||
|
|
Loading…
Reference in New Issue