Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Officially support using pathlib.Path for static_folder. #3579

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ Unreleased
argument can be passed. :issue:`3553`


Version 1.1.x
-------------

Not yet released.

- Officially support passing a :class:`pathlib.Path` for
``static_folder`` which stopped working in 1.1.2. :pr:`3579`


Version 1.1.2
-------------

Expand Down
2 changes: 1 addition & 1 deletion src/flask/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ def static_folder(self):
@static_folder.setter
def static_folder(self, value):
if value is not None:
value = value.rstrip("/\\")
value = os.fspath(value).rstrip(r"\/")
self._static_folder = value

@property
Expand Down
10 changes: 10 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,16 @@ def test_static_url_empty_path_default(app):
rv.close()


@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python >= 3.6")
def test_static_folder_with_pathlib_path(app):
from pathlib import Path

app = flask.Flask(__name__, static_folder=Path("static"))
rv = app.test_client().open("/static/index.html", method="GET")
assert rv.status_code == 200
rv.close()


def test_static_folder_with_ending_slash():
app = flask.Flask(__name__, static_folder="static/")

Expand Down