mod_wsgi icon indicating copy to clipboard operation
mod_wsgi copied to clipboard

runmodwsgi errors with newer Django settings

Open pjmichalski opened this issue 8 months ago • 3 comments

Hi, I've been using the Django management command runmodwsgi for many projects, usually without issue. However, I just started a new project and this time I got an error: "PosixPath object has no attribute 'endswith'." The error is triggered on line 1093 in /server/init.py.

I did some debugging and discovered that the "target" object on that line was a Path object pointing to the directory defined by the STATIC_ROOT setting. Older versions of Django used the os.path.join() method to define that directory, which returns a string, but new versions encourage using the pathlib.Path approach, something like STATIC_ROOT = BASE_DIR / 'collect_static'.

Obviously I can just cast that as a string within the settings file, but I imagine more and more users will have that defined as a Path object. For compatibility you might want to explicitly cast the "target" object as a string so other users don't encounter the same issue.

Thanks for the mod_wsgi package, I've used it extensively for years.

pjmichalski avatar Apr 23 '25 15:04 pjmichalski

In a test environment can you try a Django project using pathlib for STATIC_ROOT with:

pip install https://github.com/GrahamDumpleton/mod_wsgi/archive/refs/heads/develop.zip

and see if that resolves the issue.

I have made a change but haven't myself tested it yet.

GrahamDumpleton avatar Apr 23 '25 22:04 GrahamDumpleton

Hold off on that, I stuffed up the changes. :-(

GrahamDumpleton avatar Apr 23 '25 23:04 GrahamDumpleton

Okay, this time I should have got it right.

GrahamDumpleton avatar Apr 23 '25 23:04 GrahamDumpleton