[Django] #34892: Static files aren't served correctly on dev server when DEBUG and FORCE_SCRIPT_NAME are enabled

11 views
Skip to first unread message

Django

unread,
Oct 6, 2023, 8:29:37 AM10/6/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: new
Component: | Version: 4.2
contrib.staticfiles | Keywords: FORCE_SCRIPT_NAME
Severity: Normal | DEBUG STATIC_URL
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
It looks like the bug is from ancient times due to rare use of
FORCE_SCRIPT_NAME with dev server. So the version to be fixed is unknown

/contrib/staticfiles/handlers.py
{{{
def serve(self, request):
"""Serve the request path."""
-- return serve(request, self.file_path(request.path),
insecure=True)
++ return serve(request, self.file_path(request.path_info),
insecure=True)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34892>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 6, 2023, 3:57:02 PM10/6/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* status: new => closed
* resolution: => needsinfo


Comment:

Hello Eugene, thanks for your ticket.

Could you please provide some more details on how to reproduce this issue?
A description of the necessary setup and/or a small Django test project as
a reproducer would be ideal.
Even better a regression test if you would be up for it!

For now I'll mark this report as `needsinfo`, but I'll reopen as soon as
we have more information to properly triage this issue.

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:1>

Django

unread,
Oct 7, 2023, 12:49:20 AM10/7/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 1 => 0


Comment:

As far as I'm aware this is a duplicate of #30634, #7930, #31724 and few
other tickets.

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:2>

Django

unread,
Oct 7, 2023, 9:57:14 AM10/7/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by EugeneM):

Steps to reproduce:

* bootstrap
{{{
mkdir tmp && cd tmp
virtualenv venv
. venv/bin/activate
pip install "Django<5"
cd testme && mkdir static && touch static/test.css
django-admin startproject testme 10.100.100.10:9999
}}}


* nano testme/settings.py && add in the end of file and save

{{{
ALLOWED_HOSTS = ['*',]
STATICFILES_DIRS = [ f'{BASE_DIR}/static' ]
}}}

* test if all is ok in browser: http://10.100.100.10:9999/static/test.css

* nano testme/settings.py # add in the end of file and save

{{{
FORCE_SCRIPT_NAME = '/sub'
}}}

* test in browser: http://10.100.100.10:9999/static/test.css and get "Page
not found (404) ''' 'tic/test.css' ''' could not be found"

* do fix

* test if all is ok in browser: http://10.100.100.10:9999/static/test.css

Replying to [comment:2 Mariusz Felisiak]:


> As far as I'm aware this is a duplicate of #30634, #7930, #31724 and few
other tickets.

Just because somebody missed it long time ago doesn't mean it's ok.
"Page not found" message with incorrectly truncated file name hints that
something went wrong.
Moreover if you can check ''request.path'' and 'request.path_path' and
see a difference

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:3>

Django

unread,
Oct 7, 2023, 10:17:45 AM10/7/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: new

Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution:
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by EugeneM):

* status: closed => new
* resolution: needsinfo =>


Old description:

> It looks like the bug is from ancient times due to rare use of
> FORCE_SCRIPT_NAME with dev server. So the version to be fixed is unknown
>
> /contrib/staticfiles/handlers.py
> {{{
> def serve(self, request):
> """Serve the request path."""
> -- return serve(request, self.file_path(request.path),
> insecure=True)
> ++ return serve(request, self.file_path(request.path_info),
> insecure=True)
> }}}

New description:

Found out that the ticket was closed but still is interesting in mention
about incorrectly truncated path in 404 message.

Why it's ok ?

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:4>

Django

unread,
Oct 7, 2023, 10:19:18 AM10/7/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution:
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> Found out that the ticket was closed but still is interesting in mention
> about incorrectly truncated path in 404 message.
>
> Why it's ok ?

New description:

--

Comment (by EugeneM):

Found out that the ticket was closed but still is interesting in mention
about incorrectly truncated path in 404 message.

Why it's ok ?

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:5>

Django

unread,
Oct 7, 2023, 10:21:15 AM10/7/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution:
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by EugeneM:

Old description:

New description:

/contrib/staticfiles/handlers.py
{{{
def serve(self, request):
"""Serve the request path."""
-- return serve(request, self.file_path(request.path),
insecure=True)
++ return serve(request, self.file_path(request.path_info),
insecure=True)
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:6>

Django

unread,
Oct 8, 2023, 8:59:24 AM10/8/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution:
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Florian Apolloner (added)


Comment:

> Just because somebody missed it long time ago doesn't mean it's ok.

I don't understand your comment, if it's a duplicate you should leave
comment in an old ticket and don't open a new one. It doesn't matter how
old they are.

> Found out that the ticket was closed but still is interesting in mention
about incorrectly truncated path in 404 message.
> Why it's ok ?

Can you precise what do you mean?

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:7>

Django

unread,
Oct 8, 2023, 9:20:24 AM10/8/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution:
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by EugeneM):

Replying to [comment:7 Mariusz Felisiak]:


> > Just because somebody missed it long time ago doesn't mean it's ok.
>
> I don't understand your comment, if it's a duplicate you should leave
comment in an old ticket and don't open a new one. It doesn't matter how
old they are.

I left a comment in already 'closed' ticket.
I'm not sure that anyone has studied this particular problem and will ever
read the closed ticket.
So I 'renew' the ticket for sure as i wasn't able to find an option for
'reopen'.

> > Found out that the ticket was closed but still is interesting in
mention about incorrectly truncated path in 404 message.
> > Why it's ok ?
>
> Can you precise what do you mean?

I mean if you try the 'test case' that i described above. you'll see a 404
message about existing static file with wrong truncated file path to the
file in that 404 message.
I marked this with bold font in 'test case'.

When somebody had closed this ticket , it looks like somebody means 'it's
not a bug'='it's ok'.
So I'm still interesting if this 404 message with wrong truncated path is
a feature or a bug.
And if this 404 error is a feature, why the message contains wrong
truncated file path

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:8>

Django

unread,
Oct 11, 2023, 11:01:43 AM10/11/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution: duplicate

Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* status: new => closed

* resolution: => duplicate


Comment:

Hello Eugene,

I have your report and tried your instructions. While I did reproduce the
issue as you describe it, the real-world use case is unclear to me. Also,
after reading #7930, this report does seem to be a duplicate of such
ticket.

If you disagree about this being a duplicate of #7930, could you please
explain in detail why this is not a duplicate?

Regarding the fix itself, please read the
[https://code.djangoproject.com/ticket/7930#comment:13 last comment in
#7930] where it's said that nowadays the use of this setting should not be
necessary.

If you have a valid use case for this setting, please add a comment to
ticket #7930. Thank you!

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:9>

Django

unread,
Oct 12, 2023, 6:37:36 AM10/12/23
to django-...@googlegroups.com
#34892: Static files aren't served correctly on dev server when DEBUG and
FORCE_SCRIPT_NAME are enabled
-------------------------------------+-------------------------------------
Reporter: EugeneM | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 4.2
Severity: Normal | Resolution: duplicate
Keywords: FORCE_SCRIPT_NAME | Triage Stage:
DEBUG STATIC_URL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by EugeneM):

the usecase is very simple = to open webpage when debugging on DEV-server
with all dependencies with FORCE_SCRIPT_NAME enabled ( without nginx (or
other web server) and collectstatic)

It's also not a duplication of 11 years old ticket #7930, except the
subject that "FORCE_SCRIPT_NAME doesn't work correctly with dev-server".
That is truth =)
And patch proposed is also clean and very different from that was
discussed in #7930


But it's up to you, if you think all is ok.. it's ok =)

--
Ticket URL: <https://code.djangoproject.com/ticket/34892#comment:10>

Reply all
Reply to author
Forward
0 new messages