#29983 closed Cleanup/optimization (fixed)
Replace os.path with pathlib.Path in project template and docs
Reported by: | thewhisperinyourears | Owned by: | Jon Dufresne |
---|---|---|---|
Component: | Core (Other) | Version: | 2.0 |
Severity: | Normal | Keywords: | paths, settings |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Apparently there is an issue hen you are using linux (Ubuntu) and copy and paste your project to Windows. The Paths don't work. I had to change the settings in my STATICFILES_DIRS from os.path.join(BASE_DIR, 'myapp/static') to os.path.join(BASE_DIR, 'myapp', 'static')
Change History (15)
comment:1 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 years ago
I'm surprised this hasn't come up before. What does the error look like?
The documentation for STATICFILES_DIRS
days, "these paths should use Unix-style forward slashes, even on Windows". I guess the problem is that the way BASE_DIR
is generated on Windows using backslashes. It's not clear to me what Django can do about this but we'll see what Curtis comes up with.
comment:4 by , 6 years ago
Component: | contrib.staticfiles → Core (Other) |
---|---|
Patch needs improvement: | set |
Summary: | Paths when using Windows from an Ubuntu project → Replace os.path with pathlib.Path in project template and docs |
Type: | Bug → Cleanup/optimization |
The patch doesn't work because os.path.join(BASE_DIR, 'db.sqlite3')
returns a string while BASE_DIR / 'db.sqlite3'
returns a PosixPath
. The documentation would have to use str(BASE_DIR / 'db.sqlite3')
everywhere or Django would have to convert PosixPath
to string.
comment:5 by , 5 years ago
Patch needs improvement: | unset |
---|
I have resurrected the original patch with a fix for SQLite.
comment:6 by , 5 years ago
I'm not sure if various Django settings requiring a path (template DIRS
, STATIC/MEDIA_ROOT
, etc.) all support path inputs. Shouldn't we check and add tests for those before changing the project settings template?
comment:7 by , 5 years ago
Needs tests: | set |
---|---|
Owner: | changed from | to
Assigning Jon, since he's picked this up; marking as needs tests, since I think Claude is right, we have had regressions from moving to Path
.
comment:13 by , 5 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I was helping this user on IRC, and they were getting confusing errors when running "collectstatic" or "findstatic" about the path not matching.
It turned out to be a conflict with joining Windows-style paths with Unix-style paths, as mentioned above.
I'm going to look at replacing uses of os.path.join and its ilk with pathlib, which does not suffer this problem.