Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

### Fixed
- [#4218](https://github.com/plotly/dash/pull/4218) Fix `pages_folder` written with `/` on Windows, such as `pages_folder="src/pages"`: page modules were named `src/pages.home` and their inferred paths kept the folder (`/src/pages/home` instead of `/home`). Fixes [#4217](https://github.com/plotly/dash/issues/4217).

## [4.5.2] - 2026-11-27

### Changed
Expand Down
6 changes: 5 additions & 1 deletion dash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def _module_name_is_package(module_name):


def _path_to_module_name(path):
return str(path).replace(".py", "").strip(os.sep).replace(os.sep, ".")
path = str(path)
if os.altsep:
# On Windows a folder given as "app/pages" mixes "/" with "\\"
path = path.replace(os.altsep, os.sep)
return path.replace(".py", "").strip(os.sep).replace(os.sep, ".")


def _infer_module_name(page_path):
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/pages/test_pages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import pytest
Expand Down Expand Up @@ -62,6 +63,21 @@ def test_path_to_module_name(path, expected):
assert _pages._path_to_module_name(path) == expected


@pytest.mark.parametrize(
"path, expected",
[
(r"\sub_dir/custom_pages", "sub_dir.custom_pages"),
(r"\src/pages\home.py", "src.pages.home"),
(r"\sub_dir\custom_pages", "sub_dir.custom_pages"),
],
)
def test_path_to_module_name_windows_mixed_separators(monkeypatch, path, expected):
# a pages_folder written as "src/pages" on Windows mixes "/" and "\\"
monkeypatch.setattr(os, "sep", "\\")
monkeypatch.setattr(os, "altsep", "/")
assert _pages._path_to_module_name(path) == expected


@pytest.mark.parametrize(
"name, pages_folder, expected_module_name",
[
Expand Down